Merge pull request #72887 from 1000101/master

Port tests to Python
This commit is contained in:
Marek Mahut 2019-11-07 19:57:50 +01:00 committed by GitHub
commit 1a65fc1041
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 113 additions and 111 deletions

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, lib, ... }: { import ./make-test-python.nix ({ pkgs, lib, ... }: {
name = "moodle"; name = "moodle";
meta.maintainers = [ lib.maintainers.aanderse ]; meta.maintainers = [ lib.maintainers.aanderse ];
@ -15,8 +15,8 @@ import ./make-test.nix ({ pkgs, lib, ... }: {
}; };
testScript = '' testScript = ''
startAll; start_all()
$machine->waitForUnit('phpfpm-moodle.service'); machine.wait_for_unit("phpfpm-moodle.service")
$machine->succeed('curl http://localhost/') =~ /You are not logged in/ or die; machine.wait_until_succeeds("curl http://localhost/ | grep 'You are not logged in'")
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... }: import ./make-test-python.nix ({ pkgs, ... }:
{ {
name = "morty"; name = "morty";
@ -22,11 +22,9 @@ import ./make-test.nix ({ pkgs, ... }:
testScript = testScript =
{ ... }: { ... }:
'' ''
$mortyProxyWithKey->waitForUnit("default.target"); mortyProxyWithKey.wait_for_unit("default.target")
mortyProxyWithKey.wait_for_open_port(3001)
$mortyProxyWithKey->waitForOpenPort(3001); mortyProxyWithKey.succeed("curl -L 127.0.0.1:3001 | grep MortyProxy")
$mortyProxyWithKey->succeed("curl -L 127.0.0.1:3001 | grep MortyProxy");
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ lib, ... }: import ./make-test-python.nix ({ lib, ... }:
with lib; with lib;
@ -11,8 +11,8 @@ with lib;
{ services.radarr.enable = true; }; { services.radarr.enable = true; };
testScript = '' testScript = ''
$machine->waitForUnit('radarr.service'); machine.wait_for_unit("radarr.service")
$machine->waitForOpenPort('7878'); machine.wait_for_open_port("7878")
$machine->succeed("curl --fail http://localhost:7878/"); machine.succeed("curl --fail http://localhost:7878/")
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ...} : { import ./make-test-python.nix ({ pkgs, ...} : {
name = "redis"; name = "redis";
meta = with pkgs.stdenv.lib.maintainers; { meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ flokli ]; maintainers = [ flokli ];
@ -15,12 +15,10 @@ import ./make-test.nix ({ pkgs, ...} : {
}; };
testScript = '' testScript = ''
startAll; start_all()
machine.wait_for_unit("redis")
$machine->waitForUnit("redis"); machine.wait_for_open_port("6379")
$machine->waitForOpenPort("6379"); machine.succeed("redis-cli ping | grep PONG")
machine.succeed("redis-cli -s /run/redis/redis.sock ping | grep PONG")
$machine->succeed("redis-cli ping | grep PONG");
$machine->succeed("redis-cli -s /run/redis/redis.sock ping | grep PONG");
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ...} : { import ./make-test-python.nix ({ pkgs, ...} : {
name = "roundcube"; name = "roundcube";
meta = with pkgs.stdenv.lib.maintainers; { meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ globin ]; maintainers = [ globin ];
@ -21,10 +21,10 @@ import ./make-test.nix ({ pkgs, ...} : {
}; };
testScript = '' testScript = ''
$roundcube->start; roundcube.start
$roundcube->waitForUnit("postgresql.service"); roundcube.wait_for_unit("postgresql.service")
$roundcube->waitForUnit("phpfpm-roundcube.service"); roundcube.wait_for_unit("phpfpm-roundcube.service")
$roundcube->waitForUnit("nginx.service"); roundcube.wait_for_unit("nginx.service")
$roundcube->succeed("curl -sSfL http://roundcube/ | grep 'Keep me logged in'"); roundcube.succeed("curl -sSfL http://roundcube/ | grep 'Keep me logged in'")
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix { import ./make-test-python.nix {
name = "opensmtpd"; name = "opensmtpd";
nodes = { nodes = {
@ -53,14 +53,14 @@ import ./make-test.nix {
}; };
testScript = '' testScript = ''
startAll; start_all()
$server->waitForUnit("network-online.target"); server.wait_for_unit("network-online.target")
$server->waitForUnit("opensmtpd"); server.wait_for_unit("opensmtpd")
$server->waitForUnit("dovecot2"); server.wait_for_unit("dovecot2")
$server->waitForUnit("nginx"); server.wait_for_unit("nginx")
$server->waitForUnit("rss2email"); server.wait_for_unit("rss2email")
$server->waitUntilSucceeds('check-mail-landed >&2'); server.wait_until_succeeds("check-mail-landed >&2")
''; '';
} }

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ...} : import ./make-test-python.nix ({ pkgs, ...} :
{ {
name = "signal-desktop"; name = "signal-desktop";
@ -24,14 +24,14 @@ import ./make-test.nix ({ pkgs, ...} :
testScript = { nodes, ... }: let testScript = { nodes, ... }: let
user = nodes.machine.config.users.users.alice; user = nodes.machine.config.users.users.alice;
in '' in ''
startAll; start_all()
$machine->waitForX; machine.wait_for_x()
# start signal desktop # start signal desktop
$machine->execute("su - alice -c signal-desktop &"); machine.execute("su - alice -c signal-desktop &")
# wait for the "Link your phone to Signal Desktop" message # wait for the "Link your phone to Signal Desktop" message
$machine->waitForText(qr/Link your phone to Signal Desktop/); machine.wait_for_text("Link your phone to Signal Desktop")
$machine->screenshot("signal_desktop"); machine.screenshot("signal_desktop")
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ ... }: import ./make-test-python.nix ({ ... }:
{ {
name = "snapper"; name = "snapper";
@ -20,24 +20,16 @@ import ./make-test.nix ({ ... }:
}; };
testScript = '' testScript = ''
$machine->succeed("btrfs subvolume create /home/.snapshots"); machine.succeed("btrfs subvolume create /home/.snapshots")
machine.succeed("snapper -c home list")
$machine->succeed("snapper -c home list"); machine.succeed("snapper -c home create --description empty")
machine.succeed("echo test > /home/file")
$machine->succeed("snapper -c home create --description empty"); machine.succeed("snapper -c home create --description file")
machine.succeed("snapper -c home status 1..2")
$machine->succeed("echo test > /home/file"); machine.succeed("snapper -c home undochange 1..2")
$machine->succeed("snapper -c home create --description file"); machine.fail("ls /home/file")
machine.succeed("snapper -c home delete 2")
$machine->succeed("snapper -c home status 1..2"); machine.succeed("systemctl --wait start snapper-timeline.service")
machine.succeed("systemctl --wait start snapper-cleanup.service")
$machine->succeed("snapper -c home undochange 1..2");
$machine->fail("ls /home/file");
$machine->succeed("snapper -c home delete 2");
$machine->succeed("systemctl --wait start snapper-timeline.service");
$machine->succeed("systemctl --wait start snapper-cleanup.service");
''; '';
}) })

View File

@ -16,7 +16,7 @@
# See the NixOS manual for how to run this test: # See the NixOS manual for how to run this test:
# https://nixos.org/nixos/manual/index.html#sec-running-nixos-tests-interactively # https://nixos.org/nixos/manual/index.html#sec-running-nixos-tests-interactively
import ./make-test.nix ({ pkgs, ...} : import ./make-test-python.nix ({ pkgs, ...} :
let let
allowESP = "iptables --insert INPUT --protocol ESP --jump ACCEPT"; allowESP = "iptables --insert INPUT --protocol ESP --jump ACCEPT";
@ -142,7 +142,7 @@ in {
}; };
testScript = '' testScript = ''
startAll(); start_all()
$carol->waitUntilSucceeds("ping -c 1 alice"); carol.wait_until_succeeds("ping -c 1 alice")
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ...} : { import ./make-test-python.nix ({ pkgs, ...} : {
name = "telegraf"; name = "telegraf";
meta = with pkgs.stdenv.lib.maintainers; { meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ mic92 ]; maintainers = [ mic92 ];
@ -22,9 +22,9 @@ import ./make-test.nix ({ pkgs, ...} : {
}; };
testScript = '' testScript = ''
startAll; start_all()
$machine->waitForUnit("telegraf.service"); machine.wait_for_unit("telegraf.service")
$machine->waitUntilSucceeds("grep -q example /tmp/metrics.out"); machine.wait_until_succeeds("grep -q example /tmp/metrics.out")
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... }: { import ./make-test-python.nix ({ pkgs, ... }: {
name = "trickster"; name = "trickster";
meta = with pkgs.stdenv.lib.maintainers; { meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ "1000101" ]; maintainers = [ "1000101" ];
@ -15,15 +15,23 @@ import ./make-test.nix ({ pkgs, ... }: {
}; };
testScript = '' testScript = ''
startAll; start_all()
$prometheus->waitForUnit("prometheus.service"); prometheus.wait_for_unit("prometheus.service")
$prometheus->waitForOpenPort(9090); prometheus.wait_for_open_port(9090)
$prometheus->waitUntilSucceeds("curl -L http://localhost:9090/metrics | grep 'promhttp_metric_handler_requests_total{code=\"500\"} 0'"); prometheus.wait_until_succeeds(
$trickster->waitForUnit("trickster.service"); "curl -L http://localhost:9090/metrics | grep 'promhttp_metric_handler_requests_total{code=\"500\"} 0'"
$trickster->waitForOpenPort(8082); )
$trickster->waitForOpenPort(9090); trickster.wait_for_unit("trickster.service")
$trickster->waitUntilSucceeds("curl -L http://localhost:8082/metrics | grep 'promhttp_metric_handler_requests_total{code=\"500\"} 0'"); trickster.wait_for_open_port(8082)
$trickster->waitUntilSucceeds("curl -L http://prometheus:9090/metrics | grep 'promhttp_metric_handler_requests_total{code=\"500\"} 0'"); trickster.wait_for_open_port(9090)
$trickster->waitUntilSucceeds("curl -L http://localhost:9090/metrics | grep 'promhttp_metric_handler_requests_total{code=\"500\"} 0'"); trickster.wait_until_succeeds(
"curl -L http://localhost:8082/metrics | grep 'promhttp_metric_handler_requests_total{code=\"500\"} 0'"
)
trickster.wait_until_succeeds(
"curl -L http://prometheus:9090/metrics | grep 'promhttp_metric_handler_requests_total{code=\"500\"} 0'"
)
trickster.wait_until_succeeds(
"curl -L http://localhost:9090/metrics | grep 'promhttp_metric_handler_requests_total{code=\"500\"} 0'"
)
''; '';
}) })

View File

@ -5,7 +5,7 @@
# this succeeds an external client will try to connect to the port # this succeeds an external client will try to connect to the port
# mapping. # mapping.
import ./make-test.nix ({ pkgs, ... }: import ./make-test-python.nix ({ pkgs, ... }:
let let
internalRouterAddress = "192.168.3.1"; internalRouterAddress = "192.168.3.1";
@ -75,20 +75,20 @@ in
testScript = testScript =
{ nodes, ... }: { nodes, ... }:
'' ''
startAll; start_all()
# Wait for network and miniupnpd. # Wait for network and miniupnpd.
$router->waitForUnit("network-online.target"); router.wait_for_unit("network-online.target")
# $router->waitForUnit("nat"); # $router.wait_for_unit("nat")
$router->waitForUnit("firewall.service"); router.wait_for_unit("firewall.service")
$router->waitForUnit("miniupnpd"); router.wait_for_unit("miniupnpd")
$client1->waitForUnit("network-online.target"); client1.wait_for_unit("network-online.target")
$client1->succeed("upnpc -a ${internalClient1Address} 9000 9000 TCP"); client1.succeed("upnpc -a ${internalClient1Address} 9000 9000 TCP")
$client1->waitForUnit("httpd"); client1.wait_for_unit("httpd")
$client2->waitUntilSucceeds("curl http://${externalRouterAddress}:9000/"); client2.wait_until_succeeds("curl http://${externalRouterAddress}:9000/")
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, lib, ... }: import ./make-test-python.nix ({ pkgs, lib, ... }:
with lib; with lib;
@ -15,10 +15,10 @@ with lib;
}; };
testScript = '' testScript = ''
$machine->start; machine.start()
$machine->waitForX; machine.wait_for_x()
$machine->mustFail("pgrep xlock"); machine.fail("pgrep xlock")
$machine->sleep(120); machine.sleep(120)
$machine->mustSucceed("pgrep xlock"); machine.succeed("pgrep xlock")
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, lib, ... }: import ./make-test-python.nix ({ pkgs, lib, ... }:
with lib; with lib;
@ -20,14 +20,14 @@ with lib;
}; };
testScript = '' testScript = ''
$machine->start; machine.start()
$machine->waitForX; machine.wait_for_x()
# confirm proper startup # confirm proper startup
$machine->waitForUnit("yabar.service", "bob"); machine.wait_for_unit("yabar.service", "bob")
$machine->sleep(10); machine.sleep(10)
$machine->waitForUnit("yabar.service", "bob"); machine.wait_for_unit("yabar.service", "bob")
$machine->screenshot("top_bar"); machine.screenshot("top_bar")
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ...} : { import ./make-test-python.nix ({ pkgs, ...} : {
name = "zookeeper"; name = "zookeeper";
meta = with pkgs.stdenv.lib.maintainers; { meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ nequissimus ]; maintainers = [ nequissimus ];
@ -15,14 +15,20 @@ import ./make-test.nix ({ pkgs, ...} : {
}; };
testScript = '' testScript = ''
startAll; start_all()
$server->waitForUnit("zookeeper"); server.wait_for_unit("zookeeper")
$server->waitForUnit("network.target"); server.wait_for_unit("network.target")
$server->waitForOpenPort(2181); server.wait_for_open_port(2181)
$server->waitUntilSucceeds("${pkgs.zookeeper}/bin/zkCli.sh -server localhost:2181 create /foo bar"); server.wait_until_succeeds(
$server->waitUntilSucceeds("${pkgs.zookeeper}/bin/zkCli.sh -server localhost:2181 set /foo hello"); "${pkgs.zookeeper}/bin/zkCli.sh -server localhost:2181 create /foo bar"
$server->waitUntilSucceeds("${pkgs.zookeeper}/bin/zkCli.sh -server localhost:2181 get /foo | grep hello"); )
server.wait_until_succeeds(
"${pkgs.zookeeper}/bin/zkCli.sh -server localhost:2181 set /foo hello"
)
server.wait_until_succeeds(
"${pkgs.zookeeper}/bin/zkCli.sh -server localhost:2181 get /foo | grep hello"
)
''; '';
}) })