Skip to content

Commit 101a11b

Browse files
refactor: simplify test setup
1 parent 388ee1c commit 101a11b

File tree

4 files changed

+57
-60
lines changed

4 files changed

+57
-60
lines changed

default.nix

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,5 @@ rec {
156156
'';
157157
};
158158

159-
tests = import ./nix/tests/vm-basic.nix {
160-
inherit pkgs;
161-
wstModule = module;
162-
};
159+
tests = pkgs.callPackage ./nix/tests.nix { };
163160
}

nix/tests.nix

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
}

nix/tests/utils.nix

Lines changed: 0 additions & 45 deletions
This file was deleted.

nix/tests/vm-basic.nix

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)