collapse VM tests into one, use subtests

This commit is contained in:
Valentin Gagarin 2025-04-24 11:23:32 +02:00
parent f4ebf55a15
commit df9ce821de

View file

@ -22,43 +22,30 @@ let
}; };
in in
lib.mapAttrs (name: test: pkgs.testers.runNixOSTest (test // { inherit name; })) { lib.mapAttrs (name: test: pkgs.testers.runNixOSTest (test // { inherit name; })) {
application-tests = { basic = {
inherit defaults;
nodes.server = _: { imports = [ ./configuration.nix ]; };
# run all application-level tests managed by Django
# https://docs.djangoproject.com/en/5.0/topics/testing/overview/
testScript = ''
server.wait_for_unit("${name}.service")
server.succeed("manage test ${name}")
'';
};
admin = {
inherit defaults;
nodes.server = _: { imports = [ ./configuration.nix ]; };
# check that the admin interface is served
testScript = ''
server.wait_for_unit("${name}.service")
server.wait_for_open_port(8000)
server.succeed("curl --fail -L -H 'Host: example.org' http://localhost/admin")
'';
};
sass-processing = {
inherit defaults; inherit defaults;
nodes.server = _: { imports = [ ./configuration.nix ]; }; nodes.server = _: { imports = [ ./configuration.nix ]; };
extraPythonPackages = ps: with ps; [ beautifulsoup4 ]; extraPythonPackages = ps: with ps; [ beautifulsoup4 ];
# type checking on `beautifulsoup4` will error out # type checking on `beautifulsoup4` will error out
skipTypeCheck = true; skipTypeCheck = true;
# check that stylesheets are pre-processed and served
testScript = '' testScript = ''
from bs4 import BeautifulSoup
server.wait_for_unit("${name}.service") server.wait_for_unit("${name}.service")
server.wait_for_open_port(8000)
stdout = server.succeed("curl --fail -H 'Host: example.org' http://localhost") with subtest("Django application tests"):
# the CSS is auto-generated with a hash in the file name # https://docs.djangoproject.com/en/5.0/topics/testing/overview/
html = BeautifulSoup(stdout, 'html.parser') server.succeed("manage test ${name}")
css = html.find('link', type="text/css")['href']
server.succeed(f"curl --fail -H 'Host: example.org' http://localhost/{css}") with subtest("Check that admin interface is served"):
server.succeed("curl --fail -L -H 'Host: example.org' http://localhost/admin")
with subtest("Check that stylesheets are pre-processed and served"):
from bs4 import BeautifulSoup
stdout = server.succeed("curl --fail -H 'Host: example.org' http://localhost")
# the CSS is auto-generated with a hash in the file name
html = BeautifulSoup(stdout, 'html.parser')
css = html.find('link', type="text/css")['href']
server.succeed(f"curl --fail -H 'Host: example.org' http://localhost/{css}")
''; '';
}; };
} }