2022-08-01 09:27:29 +00:00
|
|
|
import ./make-test-python.nix (
|
|
|
|
{ pkgs, ... }:
|
|
|
|
let
|
|
|
|
robotsTxt = pkgs.writeText "cgit-robots.txt" ''
|
|
|
|
User-agent: *
|
|
|
|
Disallow: /
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
2022-04-05 00:02:11 +00:00
|
|
|
name = "cgit";
|
|
|
|
meta = with pkgs.lib.maintainers; {
|
|
|
|
maintainers = [ schnusch ];
|
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
|
|
|
server =
|
|
|
|
{ ... }:
|
|
|
|
{
|
|
|
|
services.cgit."localhost" = {
|
|
|
|
enable = true;
|
2022-08-01 09:27:29 +00:00
|
|
|
package = pkgs.cgit.overrideAttrs (
|
|
|
|
{ postInstall, ... }:
|
|
|
|
{
|
|
|
|
postInstall = ''
|
|
|
|
${postInstall}
|
|
|
|
cp ${robotsTxt} "$out/cgit/robots.txt"
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
);
|
2022-04-05 00:02:11 +00:00
|
|
|
nginx.location = "/(c)git/";
|
|
|
|
repos = {
|
|
|
|
some-repo = {
|
2024-06-08 21:08:55 +00:00
|
|
|
path = "/tmp/git/some-repo";
|
2022-04-05 00:02:11 +00:00
|
|
|
desc = "some-repo description";
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
|
|
|
};
|
2024-07-03 17:45:55 +00:00
|
|
|
settings = {
|
|
|
|
readme = [
|
|
|
|
":README.md"
|
|
|
|
":date.txt"
|
2024-12-10 19:26:33 +00:00
|
|
|
];
|
|
|
|
};
|
2022-04-05 00:02:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.git ];
|
2024-12-10 19:26:33 +00:00
|
|
|
};
|
2022-04-05 00:02:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
|
|
|
{ nodes, ... }:
|
|
|
|
''
|
|
|
|
start_all()
|
|
|
|
|
|
|
|
server.wait_for_unit("nginx.service")
|
|
|
|
server.wait_for_unit("network.target")
|
|
|
|
server.wait_for_open_port(80)
|
|
|
|
|
2022-08-01 09:27:29 +00:00
|
|
|
server.succeed("curl -fsS http://localhost/%28c%29git/cgit.css")
|
|
|
|
|
|
|
|
server.succeed("curl -fsS http://localhost/%28c%29git/robots.txt | diff -u - ${robotsTxt}")
|
2022-04-05 00:02:11 +00:00
|
|
|
|
|
|
|
server.succeed(
|
|
|
|
"curl -fsS http://localhost/%28c%29git/ | grep -F 'some-repo description'"
|
|
|
|
)
|
|
|
|
|
|
|
|
server.fail("curl -fsS http://localhost/robots.txt")
|
|
|
|
|
2024-06-08 21:08:55 +00:00
|
|
|
server.succeed("sudo -u cgit ${pkgs.writeShellScript "setup-cgit-test-repo" ''
|
2022-04-05 00:02:11 +00:00
|
|
|
set -e
|
2024-06-08 21:08:55 +00:00
|
|
|
git init --bare -b master /tmp/git/some-repo
|
2022-04-05 00:02:11 +00:00
|
|
|
git init -b master reference
|
|
|
|
cd reference
|
2024-06-08 21:08:55 +00:00
|
|
|
git remote add origin /tmp/git/some-repo
|
2024-07-03 17:45:55 +00:00
|
|
|
{ echo -n "cgit NixOS Test at "; date; } > date.txt
|
2022-04-05 00:02:11 +00:00
|
|
|
git add date.txt
|
|
|
|
git -c user.name=test -c user.email=test@localhost commit -m 'add date'
|
|
|
|
git push -u origin master
|
|
|
|
''}")
|
|
|
|
|
2024-07-03 17:45:55 +00:00
|
|
|
# test web download
|
2022-04-05 00:02:11 +00:00
|
|
|
server.succeed(
|
|
|
|
"curl -fsS 'http://localhost/%28c%29git/some-repo/plain/date.txt?id=master' | diff -u reference/date.txt -"
|
|
|
|
)
|
|
|
|
|
2024-07-03 17:45:55 +00:00
|
|
|
# test http clone
|
2022-04-05 00:02:11 +00:00
|
|
|
server.succeed(
|
|
|
|
"git clone http://localhost/%28c%29git/some-repo && diff -u reference/date.txt some-repo/date.txt"
|
|
|
|
)
|
2024-07-03 17:45:55 +00:00
|
|
|
|
|
|
|
# test list settings by greping for the fallback readme
|
|
|
|
server.succeed(
|
|
|
|
"curl -fsS 'http://localhost/%28c%29git/some-repo/about/' | grep -F 'cgit NixOS Test at'"
|
|
|
|
)
|
|
|
|
|
|
|
|
# add real readme
|
|
|
|
server.succeed("sudo -u cgit ${pkgs.writeShellScript "cgit-commit-readme" ''
|
|
|
|
set -e
|
|
|
|
echo '# cgit NixOS test README' > reference/README.md
|
|
|
|
git -C reference add README.md
|
|
|
|
git -C reference -c user.name=test -c user.email=test@localhost commit -m 'add readme'
|
|
|
|
git -C reference push
|
|
|
|
''}")
|
|
|
|
|
|
|
|
# test list settings by greping for the real readme
|
|
|
|
server.succeed(
|
|
|
|
"curl -fsS 'http://localhost/%28c%29git/some-repo/about/' | grep -F '# cgit NixOS test README'"
|
|
|
|
)
|
|
|
|
server.fail(
|
|
|
|
"curl -fsS 'http://localhost/%28c%29git/some-repo/about/' | grep -F 'cgit NixOS Test at'"
|
|
|
|
)
|
2022-04-05 00:02:11 +00:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
)
|