nixosTests.cgit: migrate to runTest

Part of #386873
This commit is contained in:
Piotr Kwiecinski 2025-04-04 21:08:27 +02:00
parent 6828c027d1
commit 33f2784b7c
No known key found for this signature in database
GPG key ID: EC0DE1CB9D5258B4
2 changed files with 96 additions and 98 deletions

View file

@ -294,7 +294,7 @@ in
] ./ceph-single-node-bluestore-dmcrypt.nix { }; ] ./ceph-single-node-bluestore-dmcrypt.nix { };
certmgr = handleTest ./certmgr.nix { }; certmgr = handleTest ./certmgr.nix { };
cfssl = handleTestOn [ "aarch64-linux" "x86_64-linux" ] ./cfssl.nix { }; cfssl = handleTestOn [ "aarch64-linux" "x86_64-linux" ] ./cfssl.nix { };
cgit = handleTest ./cgit.nix { }; cgit = runTest ./cgit.nix;
charliecloud = handleTest ./charliecloud.nix { }; charliecloud = handleTest ./charliecloud.nix { };
chromadb = runTest ./chromadb.nix; chromadb = runTest ./chromadb.nix;
chromium = (handleTestOn [ "aarch64-linux" "x86_64-linux" ] ./chromium.nix { }).stable or { }; chromium = (handleTestOn [ "aarch64-linux" "x86_64-linux" ] ./chromium.nix { }).stable or { };

View file

@ -1,113 +1,111 @@
import ./make-test-python.nix ( { pkgs, ... }:
{ pkgs, ... }: let
let robotsTxt = pkgs.writeText "cgit-robots.txt" ''
robotsTxt = pkgs.writeText "cgit-robots.txt" '' User-agent: *
User-agent: * Disallow: /
Disallow: / '';
''; in
in {
{ name = "cgit";
name = "cgit"; meta = with pkgs.lib.maintainers; {
meta = with pkgs.lib.maintainers; { maintainers = [ schnusch ];
maintainers = [ schnusch ]; };
};
nodes = { nodes = {
server = server =
{ ... }: { ... }:
{ {
services.cgit."localhost" = { services.cgit."localhost" = {
enable = true; enable = true;
package = pkgs.cgit.overrideAttrs ( package = pkgs.cgit.overrideAttrs (
{ postInstall, ... }: { postInstall, ... }:
{ {
postInstall = '' postInstall = ''
${postInstall} ${postInstall}
cp ${robotsTxt} "$out/cgit/robots.txt" cp ${robotsTxt} "$out/cgit/robots.txt"
''; '';
} }
); );
nginx.location = "/(c)git/"; nginx.location = "/(c)git/";
repos = { repos = {
some-repo = { some-repo = {
path = "/tmp/git/some-repo"; path = "/tmp/git/some-repo";
desc = "some-repo description"; desc = "some-repo description";
};
};
settings = {
readme = [
":README.md"
":date.txt"
];
}; };
}; };
settings = {
environment.systemPackages = [ pkgs.git ]; readme = [
":README.md"
":date.txt"
];
};
}; };
};
testScript = environment.systemPackages = [ pkgs.git ];
{ nodes, ... }: };
'' };
start_all()
server.wait_for_unit("nginx.service") testScript =
server.wait_for_unit("network.target") { nodes, ... }:
server.wait_for_open_port(80) ''
start_all()
server.succeed("curl -fsS http://localhost/%28c%29git/cgit.css") 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/robots.txt | diff -u - ${robotsTxt}") server.succeed("curl -fsS http://localhost/%28c%29git/cgit.css")
server.succeed( server.succeed("curl -fsS http://localhost/%28c%29git/robots.txt | diff -u - ${robotsTxt}")
"curl -fsS http://localhost/%28c%29git/ | grep -F 'some-repo description'"
)
server.fail("curl -fsS http://localhost/robots.txt") server.succeed(
"curl -fsS http://localhost/%28c%29git/ | grep -F 'some-repo description'"
)
server.succeed("sudo -u cgit ${pkgs.writeShellScript "setup-cgit-test-repo" '' server.fail("curl -fsS http://localhost/robots.txt")
set -e
git init --bare -b master /tmp/git/some-repo
git init -b master reference
cd reference
git remote add origin /tmp/git/some-repo
{ echo -n "cgit NixOS Test at "; 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
''}")
# test web download server.succeed("sudo -u cgit ${pkgs.writeShellScript "setup-cgit-test-repo" ''
server.succeed( set -e
"curl -fsS 'http://localhost/%28c%29git/some-repo/plain/date.txt?id=master' | diff -u reference/date.txt -" git init --bare -b master /tmp/git/some-repo
) git init -b master reference
cd reference
git remote add origin /tmp/git/some-repo
{ echo -n "cgit NixOS Test at "; 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
''}")
# test http clone # test web download
server.succeed( server.succeed(
"git clone http://localhost/%28c%29git/some-repo && diff -u reference/date.txt some-repo/date.txt" "curl -fsS 'http://localhost/%28c%29git/some-repo/plain/date.txt?id=master' | diff -u reference/date.txt -"
) )
# test list settings by greping for the fallback readme # test http clone
server.succeed( server.succeed(
"curl -fsS 'http://localhost/%28c%29git/some-repo/about/' | grep -F 'cgit NixOS Test at'" "git clone http://localhost/%28c%29git/some-repo && diff -u reference/date.txt some-repo/date.txt"
) )
# add real readme # test list settings by greping for the fallback readme
server.succeed("sudo -u cgit ${pkgs.writeShellScript "cgit-commit-readme" '' server.succeed(
set -e "curl -fsS 'http://localhost/%28c%29git/some-repo/about/' | grep -F 'cgit NixOS Test at'"
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 # add real readme
server.succeed( server.succeed("sudo -u cgit ${pkgs.writeShellScript "cgit-commit-readme" ''
"curl -fsS 'http://localhost/%28c%29git/some-repo/about/' | grep -F '# cgit NixOS test README'" set -e
) echo '# cgit NixOS test README' > reference/README.md
server.fail( git -C reference add README.md
"curl -fsS 'http://localhost/%28c%29git/some-repo/about/' | grep -F 'cgit NixOS Test at'" 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'"
)
'';
}