about summary refs log tree commit diff
path: root/nixos/tests/cgit.nix
blob: 6aed06adefdff6d1f913dfe651c55a7a11b3ec7c (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
import ./make-test-python.nix ({ pkgs, ... }:
let
  robotsTxt = pkgs.writeText "cgit-robots.txt" ''
    User-agent: *
    Disallow: /
  '';
in {
  name = "cgit";
  meta = with pkgs.lib.maintainers; {
    maintainers = [ schnusch ];
  };

  nodes = {
    server = { ... }: {
      services.cgit."localhost" = {
        enable = true;
        package = pkgs.cgit.overrideAttrs ({ postInstall, ... }: {
          postInstall = ''
            ${postInstall}
            cp ${robotsTxt} "$out/cgit/robots.txt"
          '';
        });
        nginx.location = "/(c)git/";
        repos = {
          some-repo = {
            path = "/srv/git/some-repo";
            desc = "some-repo description";
          };
        };
      };

      environment.systemPackages = [ pkgs.git ];
    };
  };

  testScript = { nodes, ... }: ''
    start_all()

    server.wait_for_unit("nginx.service")
    server.wait_for_unit("network.target")
    server.wait_for_open_port(80)

    server.succeed("curl -fsS http://localhost/%28c%29git/cgit.css")

    server.succeed("curl -fsS http://localhost/%28c%29git/robots.txt | diff -u - ${robotsTxt}")

    server.succeed(
        "curl -fsS http://localhost/%28c%29git/ | grep -F 'some-repo description'"
    )

    server.fail("curl -fsS http://localhost/robots.txt")

    server.succeed("${pkgs.writeShellScript "setup-cgit-test-repo" ''
      set -e
      git init --bare -b master /srv/git/some-repo
      git init -b master reference
      cd reference
      git remote add origin /srv/git/some-repo
      date > date.txt
      git add date.txt
      git -c user.name=test -c user.email=test@localhost commit -m 'add date'
      git push -u origin master
    ''}")

    server.succeed(
        "curl -fsS 'http://localhost/%28c%29git/some-repo/plain/date.txt?id=master' | diff -u reference/date.txt -"
    )

    server.succeed(
       "git clone http://localhost/%28c%29git/some-repo && diff -u reference/date.txt some-repo/date.txt"
    )
  '';
})