-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtests.nix
151 lines (126 loc) · 3.1 KB
/
tests.nix
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# These are lxd-snapper's acceptance tests; you can run them using:
#
# ```
# nix flake check -j4
# ```
{ nixpkgs
, nixpkgs--lxd-4
, nixpkgs--lxd-5
, nixpkgs--lxd-6
, lxd-snapper
}:
let
inherit (pkgs) lib;
pkgs = import nixpkgs {
system = "x86_64-linux";
};
lxdContainer = import "${nixpkgs}/nixos/release.nix" {
configuration = {
documentation = {
enable = lib.mkForce false;
};
environment = {
noXlibs = lib.mkForce true;
};
};
};
mkTest = testPath: testName: testNixpkgs:
let
testPkgs = import testNixpkgs {
system = "x86_64-linux";
};
testScript =
let
prelude = import ./tests/prelude.py.nix {
inherit testPath;
lxdConfig = ./tests/_fixtures/lxd-config.yaml;
lxdContainerMeta = lxdContainer.lxdContainerMeta.${pkgs.system};
lxdContainerImage = lxdContainer.lxdContainerImage.${pkgs.system};
};
in
prelude
+ "\n\n"
+ (builtins.readFile "${testPath}/test.py");
in
import "${testPath}/test.nix" {
fw = rec {
mkNode = config @ { ... }:
lib.mkMerge [
{
boot = {
supportedFilesystems = [ "zfs" ];
};
environment = {
systemPackages = with pkgs; [
jq
lxd-snapper
];
};
networking = {
hostId = "01234567";
};
virtualisation = {
cores = 2;
memorySize = 2048;
diskSize = 2048;
lxd = {
enable = true;
package = testPkgs.lxd;
};
qemu = {
options = [
"-rtc base=2018-01-01T12:00:00"
];
};
};
}
config
];
mkTest = { nodes }:
pkgs.nixosTest {
inherit testScript nodes;
name = testName;
};
mkDefaultTest = mkTest {
nodes = {
machine = mkNode { };
};
};
};
};
mkTests = { tests, lxds }:
let
testCombinations =
lib.cartesianProduct {
testPath = tests;
testLxd = lxds;
};
mkTestFromCombination = { testPath, testLxd }:
let
testName = "${builtins.baseNameOf testPath}.lxd-${testLxd.version}";
in
{
name = testName;
value = mkTest testPath testName testLxd.nixpkgs;
};
in
builtins.listToAttrs
(builtins.map
mkTestFromCombination
testCombinations);
in
mkTests {
tests = [
./tests/backup-and-prune
./tests/backup-and-prune-with-projects
./tests/backup-and-prune-with-remotes
./tests/dry-run
./tests/hooks
./tests/timeout
];
lxds = [
{ version = "4"; nixpkgs = nixpkgs--lxd-4; }
{ version = "5"; nixpkgs = nixpkgs--lxd-5; }
{ version = "6"; nixpkgs = nixpkgs--lxd-6; }
];
}