From 8a1a16c4e5f394404fac75f8178912cc48ea5651 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Tue, 24 Dec 2024 01:25:29 +0100 Subject: feat(tests/back): Init --- tests/by-name/ba/back/test.nix | 121 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 tests/by-name/ba/back/test.nix 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", ""); + ''; + } -- cgit 1.4.1