blob: a81d5614b446178e8d7e4eb8c666364386a01e9d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
{ lib, config, extendModules, ... }:
let
inherit (lib)
mkOption
types
;
indent = lib.replaceStrings ["\n"] ["\n "];
execTestCase = testCase: ''
### TEST ${testCase.name}: ${testCase.description} ###
with subtest("${testCase.description}"):
# Setup
${indent testCase.setupScript}
# Test
${indent testCase.script}
'';
in
{
options = {
setupScript = mkOption {
type = types.lines;
description = ''
Python code that runs before the main test.
Variables defined by this code will be available in the test.
'';
default = "";
};
testCases = mkOption {
description = ''
The test cases. See `testScript`.
'';
type = types.listOf (types.submodule {
options.name = mkOption {
type = types.str;
description = ''
The name of the test case.
A repository with that name will be set up on the gitea server and locally.
'';
};
options.description = mkOption {
type = types.str;
description = ''
A description of the test case.
'';
};
options.setupScript = mkOption {
type = types.lines;
description = ''
Python code that runs before the test case.
'';
default = "";
};
options.script = mkOption {
type = types.lines;
description = ''
Python code that runs the test.
Variables defined by the global `setupScript`, as well as `testCases.*.setupScript` will be available here.
'';
};
});
};
};
config = {
nodes.client = {
environment.variables = {
_NIX_FORCE_HTTP = "1";
};
nix.settings.experimental-features = ["nix-command" "flakes"];
};
setupScript = ''
'';
testScript = ''
start_all();
${config.setupScript}
### SETUP COMPLETE ###
${lib.concatStringsSep "\n" (map execTestCase config.testCases)}
'';
};
}
|