summary refs log tree commit diff stats
path: root/tests/by-name/ba/back/test.nix
blob: 220d10004efa5d692e2720beab1a5a251d55a316 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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", "");
    '';
  }