-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.nix
76 lines (69 loc) · 2.92 KB
/
test.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
{ testers, git, builder, writeShellScript, lib, fenceStart, fenceEnd }:
let
tests = {
singleHookTest.hooks = [{
type = "pre-commit";
cmd = "foo";
}];
multipleHooksTest.hooks = [
{
type = "post-merge";
cmd = "foo";
}
{
type = "post-checkout";
cmd = "foo";
}
];
singleHookAppendTest.hooks = [{
type = "pre-checkout";
cmd = "foo";
}];
singleHookModifyTest.hooks = [{
type = "pre-merge";
cmd = "foo";
}];
};
in
testers.nixosTest {
name = "file-test";
nodes.vm = {
environment.systemPackages = [ git ];
};
testScript = ''
class TestFolder(object):
def __enter__(self):
vm.succeed("git init")
def __exit__(self, *args):
vm.succeed("rm -r .git")
def surroundWithFences(s: str):
return f"${fenceStart}\n{s}\n${fenceEnd}\n"
with TestFolder():
vm.succeed("${builder { inherit (tests.singleHookTest) hooks; inherit git writeShellScript; }}")
actual = vm.succeed("cat .git/hooks/${(builtins.head tests.singleHookTest.hooks).type}")
expected = surroundWithFences("${(builtins.head tests.singleHookTest.hooks).cmd}")
assert actual == expected, f"Expected '{expected}' but was '{actual}'"
with TestFolder():
vm.succeed("${builder { inherit (tests.multipleHooksTest) hooks; inherit git writeShellScript; }}")
actual = vm.succeed("cat .git/hooks/${(builtins.head tests.multipleHooksTest.hooks).type}")
expected = surroundWithFences("${(builtins.head tests.multipleHooksTest.hooks).cmd}")
assert actual == expected, f"Expected '{expected}' but was '{actual}'"
with TestFolder():
previousContent = "bar"
vm.succeed(f"echo {previousContent} > .git/hooks/${(builtins.head tests.singleHookAppendTest.hooks).type}")
vm.succeed("${builder { inherit (tests.singleHookAppendTest) hooks; inherit git writeShellScript; }}")
actual = vm.succeed("cat .git/hooks/${(builtins.head tests.singleHookAppendTest.hooks).type}")
expected = (f"{previousContent}\n"
+ surroundWithFences("${(builtins.head tests.singleHookAppendTest.hooks).cmd}"))
assert actual == expected, f"Expected '{expected}' but was '{actual}'"
with TestFolder():
vm.succeed("${builder { inherit (tests.singleHookModifyTest) hooks; inherit git writeShellScript; }}")
user_appended_content = "bar"
vm.succeed(f"echo {user_appended_content} >> .git/hooks/${(builtins.head tests.singleHookModifyTest.hooks).type}")
vm.succeed("${builder { inherit (tests.singleHookModifyTest) hooks; inherit git writeShellScript; }}")
actual = vm.succeed("cat .git/hooks/${(builtins.head tests.singleHookModifyTest.hooks).type}")
expected = (f"{user_appended_content}\n"
+ surroundWithFences("${(builtins.head tests.singleHookModifyTest.hooks).cmd}"))
assert actual == expected, f"Expected '{expected}' but was '{actual}'"
'';
}