{ lib, pkgs }: let # TODO: specify project/service name globally name = "panel"; defaults = { # XXX: we have to duplicate this here despite it being defined in the service module, otherwise the test framework will error out nixpkgs.overlays = lib.mkForce [ (import ./overlay.nix) ]; services.${name} = { enable = true; production = false; restart = "no"; domain = "example.com"; secrets = { SECRET_KEY = pkgs.writeText "SECRET_KEY" "secret"; }; }; virtualisation = { memorySize = 2048; cores = 2; }; }; in lib.mapAttrs (name: test: pkgs.testers.runNixOSTest (test // { inherit name; })) { basic = { inherit defaults; nodes.server = _: { imports = [ ./configuration.nix ]; }; extraPythonPackages = ps: with ps; [ beautifulsoup4 ]; # type checking on `beautifulsoup4` will error out skipTypeCheck = true; testScript = '' server.wait_for_unit("${name}.service") with subtest("Django application tests"): # https://docs.djangoproject.com/en/5.0/topics/testing/overview/ server.succeed("manage test ${name}") 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}") ''; }; }