summary refs log tree commit diff stats
path: root/tests/by-name/ba
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-12-24 01:25:29 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-12-24 01:25:29 +0100
commit8a1a16c4e5f394404fac75f8178912cc48ea5651 (patch)
tree557532d5a4e9251cd9ce753593dbbd49df19ea8f /tests/by-name/ba
parentfeat(modules/back): Init (diff)
downloadnixos-server-8a1a16c4e5f394404fac75f8178912cc48ea5651.tar.gz
nixos-server-8a1a16c4e5f394404fac75f8178912cc48ea5651.zip
feat(tests/back): Init
Diffstat (limited to 'tests/by-name/ba')
-rw-r--r--tests/by-name/ba/back/test.nix121
1 files changed, 121 insertions, 0 deletions
diff --git a/tests/by-name/ba/back/test.nix b/tests/by-name/ba/back/test.nix
new file mode 100644
index 0000000..220d100
--- /dev/null
+++ b/tests/by-name/ba/back/test.nix
@@ -0,0 +1,121 @@
+{
+  nixos-lib,
+  pkgsUnstable,
+  nixpkgs-unstable,
+  vhackPackages,
+  pkgs,
+  extraModules,
+  nixLib,
+  ...
+}: let
+  gitRepoPath = "/srv/test/repo";
+
+  domain = "server";
+in
+  nixos-lib.runTest {
+    hostPkgs = pkgs; # the Nixpkgs package set used outside the VMs
+
+    name = "back";
+
+    node = {
+      specialArgs = {inherit pkgsUnstable vhackPackages nixpkgs-unstable nixLib;};
+
+      # Use the nixpkgs as constructed by the `nixpkgs.*` options
+      pkgs = null;
+    };
+
+    nodes = {
+      server = {config, ...}: {
+        environment.systemPackages = [pkgs.git pkgs.git-bug pkgs.gawk];
+
+        imports =
+          extraModules
+          ++ [
+            ../../../../modules
+          ];
+
+        vhack = {
+          nginx = {
+            enable = true;
+            selfsign = true;
+          };
+          git-server = {
+            enable = true;
+          };
+          back = {
+            enable = true;
+            repositories = {
+              "${gitRepoPath}" = {
+                enable = true;
+                domain = "${domain}";
+                port = 9220;
+              };
+            };
+          };
+        };
+      };
+
+      client = {...}: {
+        environment.systemPackages = [pkgs.curl];
+      };
+    };
+
+    testScript = {nodes, ...}:
+    /*
+    python
+    */
+    ''
+      start_all()
+
+      with subtest("can setup git-bug issues on server"):
+        server.succeed("${pkgs.writeShellScript "setup-git-repo" ''
+        set -ex
+
+        mkdir --parents "${gitRepoPath}"
+        cd "${gitRepoPath}"
+
+        git init
+
+        git bug user create --avatar "" --email "test@email.org" --name "test user" --non-interactive
+
+        git bug add \
+        --title "Some bug title" \
+        --message "A long description of the bug. Probably has some code segments, maybe even *markdown* mark_up_ or other things" \
+        --non-interactive
+
+        git bug add \
+        --title "Second bug title" \
+        --message "" \
+        --non-interactive
+
+        git bug add \
+        --title "Third bug title" \
+        --message "" \
+        --non-interactive
+
+        git bug select "$(git bug ls --format plain | awk '{print $1}' | head -n 1)"
+
+        git bug comment add --message "Some comment message" --non-interactive
+        git bug comment add --message "Second comment message" --non-interactive
+
+        # NOTE(@bpeetz): Currently, the `back` module assumes that the git user can write
+        # to the repository, as such we need to provide write access here <2024-12-24>
+        chown --recursive git:git "${gitRepoPath}"
+      ''}")
+
+      with subtest("back server starts"):
+        server.wait_for_unit("${builtins.replaceStrings ["/"] ["_"] "back-${gitRepoPath}-${domain}.service"}")
+
+      with subtest("client can access the server"):
+        client.succeed("${pkgs.writeShellScript "curl-back" ''
+        set -xe
+
+        curl --insecure --silent --fail --show-error "https://${domain}/issues/open" --output /root/issues.html
+
+        grep -- '- 2 comments' /root/issues.html
+        grep -- 'Second bug title' /root/issues.html
+      ''}")
+
+      client.copy_from_vm("/root/issues.html", "");
+    '';
+  }