|
| 1 | +{ lib, pkgs }: |
| 2 | +let |
| 3 | + # TODO: specify project/service name globally |
| 4 | + application = "web-security-tracker"; |
| 5 | + defaults = { |
| 6 | + documentation.enable = lib.mkDefault false; |
| 7 | + |
| 8 | + virtualisation = { |
| 9 | + memorySize = 2048; |
| 10 | + cores = 2; |
| 11 | + }; |
| 12 | + |
| 13 | + services.${application} = { |
| 14 | + enable = true; |
| 15 | + production = false; |
| 16 | + restart = "no"; # fail fast |
| 17 | + domain = "example.org"; |
| 18 | + secrets = { |
| 19 | + SECRET_KEY = pkgs.writeText "SECRET_KEY" "secret"; |
| 20 | + GH_CLIENT_ID = pkgs.writeText "gh_client" "bonjour"; |
| 21 | + GH_SECRET = pkgs.writeText "gh_secret" "secret"; |
| 22 | + GH_WEBHOOK_SECRET = pkgs.writeText "gh_secret" "webhook-secret"; |
| 23 | + }; |
| 24 | + }; |
| 25 | + }; |
| 26 | +in |
| 27 | +lib.mapAttrs (name: test: pkgs.testers.runNixOSTest (test // { inherit name defaults; })) { |
| 28 | + application-tests = { |
| 29 | + nodes.server = _: { imports = [ ./configuration.nix ]; }; |
| 30 | + # run all application-level tests managed by Django |
| 31 | + # https://docs.djangoproject.com/en/5.0/topics/testing/overview/ |
| 32 | + testScript = '' |
| 33 | + server.wait_for_unit("${application}-server.service") |
| 34 | + server.succeed("manage test shared") |
| 35 | + server.succeed("manage test webview") |
| 36 | + ''; |
| 37 | + }; |
| 38 | + css = { |
| 39 | + nodes.server = _: { imports = [ ./web-security-tracker.nix ]; }; |
| 40 | + # check that the style sheet is served |
| 41 | + testScript = '' |
| 42 | + server.wait_for_unit("${application}-server.service") |
| 43 | + server.wait_for_open_port(8000) |
| 44 | + machine.succeed("curl --fail -H 'Host: example.org' http://127.0.0.1:80/static/style.css") |
| 45 | + ''; |
| 46 | + }; |
| 47 | + admin = { |
| 48 | + nodes.server = _: { imports = [ ./web-security-tracker.nix ]; }; |
| 49 | + # check that the admin interface is served |
| 50 | + testScript = '' |
| 51 | + server.wait_for_unit("${application}-server.service") |
| 52 | + server.wait_for_open_port(8000) |
| 53 | + server.succeed("curl --fail -L -H 'Host: example.org' http://localhost/admin") |
| 54 | + ''; |
| 55 | + }; |
| 56 | +} |
0 commit comments