git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #75695 from kampka/port-tests

Port NixOS tests to python

commitfc47ec691f8b6f91c22c54b03bce3dc443131978 authorDmitry Kalinkin <dmitry.kalinkin@gmail.com> dateTue 17 Dec 2019, 21:45 (7 years ago) parentf7b6824a6ac3fd
6 files changed+44−36
nixos/tests/haproxy.nix+9−7 nixos/tests/initrd-network.nix+4−4 nixos/tests/leaps.nix+7−5 nixos/tests/lidarr.nix+6−4 nixos/tests/mailcatcher.nix+10−6 nixos/tests/wireguard/namespaces.nix+8−10
nixos/tests/haproxy.nix+9−7
@@ -1,4 +1,4 @@
1−import ./make-test.nix ({ pkgs, ...}: {
1+import ./make-test-python.nix ({ pkgs, ...}: {
22 name = "haproxy";
33 nodes = {
44 machine = { ... }: {
@@ -33,11 +33,13 @@ import ./make-test.nix ({ pkgs, ...}: {
3333 };
3434 };
3535 testScript = ''
36− startAll;
37− $machine->waitForUnit('multi-user.target');
38− $machine->waitForUnit('haproxy.service');
39− $machine->waitForUnit('httpd.service');
40− $machine->succeed('curl -k http://localhost:80/index.txt | grep "We are all good!"');
41− $machine->succeed('curl -k http://localhost:80/metrics | grep haproxy_process_pool_allocated_bytes');
36+ start_all()
37+ machine.wait_for_unit("multi-user.target")
38+ machine.wait_for_unit("haproxy.service")
39+ machine.wait_for_unit("httpd.service")
40+ assert "We are all good!" in machine.succeed("curl -k http://localhost:80/index.txt")
41+ assert "haproxy_process_pool_allocated_bytes" in machine.succeed(
42+ "curl -k http://localhost:80/metrics"
43+ )
4244 '';
4345})
nixos/tests/initrd-network.nix+4−4
@@ -1,4 +1,4 @@
1−import ./make-test.nix ({ pkgs, ...} : {
1+import ./make-test-python.nix ({ pkgs, ...} : {
22 name = "initrd-network";
33
44 meta.maintainers = [ pkgs.stdenv.lib.maintainers.eelco ];
@@ -15,8 +15,8 @@ import ./make-test.nix ({ pkgs, ...} : {
1515
1616 testScript =
1717 ''
18− startAll;
19− $machine->waitForUnit("multi-user.target");
20− $machine->succeed("ip link >&2");
18+ start_all()
19+ machine.wait_for_unit("multi-user.target")
20+ machine.succeed("ip link >&2")
2121 '';
2222})
nixos/tests/leaps.nix+7−5
@@ -1,4 +1,4 @@
1−import ./make-test.nix ({ pkgs, ... }:
1+import ./make-test-python.nix ({ pkgs, ... }:
22
33{
44 name = "leaps";
@@ -22,9 +22,11 @@ import ./make-test.nix ({ pkgs, ... }:
2222
2323 testScript =
2424 ''
25− startAll;
26− $server->waitForOpenPort(6666);
27− $client->waitForUnit("network.target");
28− $client->succeed("${pkgs.curl}/bin/curl http://server:6666/leaps/ | grep -i 'leaps'");
25+ start_all()
26+ server.wait_for_open_port(6666)
27+ client.wait_for_unit("network.target")
28+ assert "leaps" in client.succeed(
29+ "${pkgs.curl}/bin/curl http://server:6666/leaps/"
30+ )
2931 '';
3032})
nixos/tests/lidarr.nix+6−4
@@ -1,4 +1,4 @@
1−import ./make-test.nix ({ lib, ... }:
1+import ./make-test-python.nix ({ lib, ... }:
22
33with lib;
44
@@ -11,8 +11,10 @@ with lib;
1111 { services.lidarr.enable = true; };
1212
1313 testScript = ''
14− $machine->waitForUnit('lidarr.service');
15− $machine->waitForOpenPort('8686');
16− $machine->succeed("curl --fail http://localhost:8686/");
14+ start_all()
15+
16+ machine.wait_for_unit("lidarr.service")
17+ machine.wait_for_open_port("8686")
18+ machine.succeed("curl --fail http://localhost:8686/")
1719 '';
1820})
nixos/tests/mailcatcher.nix+10−6
@@ -1,4 +1,4 @@
1−import ./make-test.nix ({ lib, ... }:
1+import ./make-test-python.nix ({ lib, ... }:
22
33{
44 name = "mailcatcher";
@@ -16,11 +16,15 @@ import ./make-test.nix ({ lib, ... }:
1616 };
1717
1818 testScript = ''
19− startAll;
19+ start_all()
2020
21− $machine->waitForUnit('mailcatcher.service');
22− $machine->waitForOpenPort('1025');
23− $machine->succeed('echo "this is the body of the email" | mail -s "subject" root@example.org');
24− $machine->succeed('curl http://localhost:1080/messages/1.source') =~ /this is the body of the email/ or die;
21+ machine.wait_for_unit("mailcatcher.service")
22+ machine.wait_for_open_port("1025")
23+ machine.succeed(
24+ 'echo "this is the body of the email" | mail -s "subject" root@example.org'
25+ )
26+ assert "this is the body of the email" in machine.succeed(
27+ "curl http://localhost:1080/messages/1.source"
28+ )
2529 '';
2630})
nixos/tests/wireguard/namespaces.nix+8−10
@@ -13,7 +13,7 @@ let
1313
1414in
1515
16−import ../make-test.nix ({ pkgs, ...} : {
16+import ../make-test-python.nix ({ pkgs, ...} : {
1717 name = "wireguard-with-namespaces";
1818 meta = with pkgs.stdenv.lib.maintainers; {
1919 maintainers = [ asymmetric ];
@@ -65,16 +65,14 @@ import ../make-test.nix ({ pkgs, ...} : {
6565 };
6666
6767 testScript = ''
68− startAll();
68+ start_all()
6969
70− $peer0->waitForUnit("wireguard-wg0.service");
71− $peer1->waitForUnit("wireguard-wg0.service");
72− $peer2->waitForUnit("wireguard-wg0.service");
73− $peer3->waitForUnit("wireguard-wg0.service");
70+ for machine in peer0, peer1, peer2, peer3:
71+ machine.wait_for_unit("wireguard-wg0.service")
7472
75− $peer0->succeed("ip -n ${socketNamespace} link show wg0");
76− $peer1->succeed("ip -n ${interfaceNamespace} link show wg0");
77− $peer2->succeed("ip -n ${interfaceNamespace} link show wg0");
78− $peer3->succeed("ip link show wg0");
73+ peer0.succeed("ip -n ${socketNamespace} link show wg0")
74+ peer1.succeed("ip -n ${interfaceNamespace} link show wg0")
75+ peer2.succeed("ip -n ${interfaceNamespace} link show wg0")
76+ peer3.succeed("ip link show wg0")
7977 '';
8078})