Merge pull request #73131 from 1000101/port-tests-to-python

Port tests to python
This commit is contained in:
Florian Klink 2019-11-22 20:47:24 +01:00 committed by GitHub
commit c81e4f10c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 142 additions and 112 deletions

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... }: { import ./make-test-python.nix ({ pkgs, ... }: {
name = "clickhouse"; name = "clickhouse";
meta.maintainers = with pkgs.stdenv.lib.maintainers; [ ma27 ]; meta.maintainers = with pkgs.stdenv.lib.maintainers; [ ma27 ];
@ -14,12 +14,18 @@ import ./make-test.nix ({ pkgs, ... }: {
selectQuery = pkgs.writeText "select.sql" "SELECT * from `demo`"; selectQuery = pkgs.writeText "select.sql" "SELECT * from `demo`";
in in
'' ''
$machine->start(); machine.start()
$machine->waitForUnit("clickhouse.service"); machine.wait_for_unit("clickhouse.service")
$machine->waitForOpenPort(9000); machine.wait_for_open_port(9000)
$machine->succeed("cat ${tableDDL} | clickhouse-client"); machine.succeed(
$machine->succeed("cat ${insertQuery} | clickhouse-client"); "cat ${tableDDL} | clickhouse-client"
$machine->succeed("cat ${selectQuery} | clickhouse-client | grep foo"); )
machine.succeed(
"cat ${insertQuery} | clickhouse-client"
)
machine.succeed(
"cat ${selectQuery} | clickhouse-client | grep foo"
)
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ...} : { import ./make-test-python.nix ({ pkgs, ...} : {
name = "deluge"; name = "deluge";
meta = with pkgs.stdenv.lib.maintainers; { meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ flokli ]; maintainers = [ flokli ];
@ -45,18 +45,20 @@ import ./make-test.nix ({ pkgs, ...} : {
}; };
testScript = '' testScript = ''
startAll; start_all()
$simple->waitForUnit("deluged"); simple.wait_for_unit("deluged")
$simple->waitForUnit("delugeweb"); simple.wait_for_unit("delugeweb")
$simple->waitForOpenPort("8112"); simple.wait_for_open_port("8112")
$declarative->waitForUnit("network.target"); declarative.wait_for_unit("network.target")
$declarative->waitUntilSucceeds("curl --fail http://simple:8112"); declarative.wait_until_succeeds("curl --fail http://simple:8112")
$declarative->waitForUnit("deluged"); declarative.wait_for_unit("deluged")
$declarative->waitForUnit("delugeweb"); declarative.wait_for_unit("delugeweb")
$declarative->waitUntilSucceeds("curl --fail http://declarative:3142"); declarative.wait_until_succeeds("curl --fail http://declarative:3142")
$declarative->succeed("deluge-console 'help' | grep -q 'rm - Remove a torrent'"); declarative.succeed("deluge-console 'help' | grep -q 'rm - Remove a torrent'")
$declarative->succeed("deluge-console 'connect 127.0.0.1:58846 andrew password; help' | grep -q 'rm - Remove a torrent'"); declarative.succeed(
"deluge-console 'connect 127.0.0.1:58846 andrew password; help' | grep -q 'rm - Remove a torrent'"
)
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... } : { import ./make-test-python.nix ({ pkgs, ... } : {
name = "fancontrol"; name = "fancontrol";
machine = machine =
@ -19,7 +19,10 @@ import ./make-test.nix ({ pkgs, ... } : {
# This configuration cannot be valid for the test VM, so it's expected to get an 'outdated' error. # This configuration cannot be valid for the test VM, so it's expected to get an 'outdated' error.
testScript = '' testScript = ''
$machine->waitForUnit("fancontrol.service"); start_all()
$machine->waitUntilSucceeds("journalctl -eu fancontrol | grep 'Configuration appears to be outdated'"); machine.wait_for_unit("fancontrol.service")
machine.wait_until_succeeds(
"journalctl -eu fancontrol | grep 'Configuration appears to be outdated'"
)
''; '';
}) })

View File

@ -1,6 +1,6 @@
# Test the firewall module. # Test the firewall module.
import ./make-test.nix ( { pkgs, ... } : { import ./make-test-python.nix ( { pkgs, ... } : {
name = "firewall"; name = "firewall";
meta = with pkgs.stdenv.lib.maintainers; { meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ eelco ]; maintainers = [ eelco ];
@ -36,30 +36,30 @@ import ./make-test.nix ( { pkgs, ... } : {
testScript = { nodes, ... }: let testScript = { nodes, ... }: let
newSystem = nodes.walled2.config.system.build.toplevel; newSystem = nodes.walled2.config.system.build.toplevel;
in '' in ''
$walled->start; start_all()
$attacker->start;
$walled->waitForUnit("firewall"); walled.wait_for_unit("firewall")
$walled->waitForUnit("httpd"); walled.wait_for_unit("httpd")
$attacker->waitForUnit("network.target"); attacker.wait_for_unit("network.target")
# Local connections should still work. # Local connections should still work.
$walled->succeed("curl -v http://localhost/ >&2"); walled.succeed("curl -v http://localhost/ >&2")
# Connections to the firewalled machine should fail, but ping should succeed. # Connections to the firewalled machine should fail, but ping should succeed.
$attacker->fail("curl --fail --connect-timeout 2 http://walled/ >&2"); attacker.fail("curl --fail --connect-timeout 2 http://walled/ >&2")
$attacker->succeed("ping -c 1 walled >&2"); attacker.succeed("ping -c 1 walled >&2")
# Outgoing connections/pings should still work. # Outgoing connections/pings should still work.
$walled->succeed("curl -v http://attacker/ >&2"); walled.succeed("curl -v http://attacker/ >&2")
$walled->succeed("ping -c 1 attacker >&2"); walled.succeed("ping -c 1 attacker >&2")
# If we stop the firewall, then connections should succeed. # If we stop the firewall, then connections should succeed.
$walled->stopJob("firewall"); walled.stop_job("firewall")
$attacker->succeed("curl -v http://walled/ >&2"); attacker.succeed("curl -v http://walled/ >&2")
# Check whether activation of a new configuration reloads the firewall. # Check whether activation of a new configuration reloads the firewall.
$walled->succeed("${newSystem}/bin/switch-to-configuration test 2>&1" . walled.succeed(
" | grep -qF firewall.service"); "${newSystem}/bin/switch-to-configuration test 2>&1 | grep -qF firewall.service"
)
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... }: { import ./make-test-python.nix ({ pkgs, ... }: {
name = "fish"; name = "fish";
machine = machine =
@ -14,8 +14,11 @@ import ./make-test.nix ({ pkgs, ... }: {
testScript = testScript =
'' ''
$machine->waitForFile("/etc/fish/generated_completions/coreutils.fish"); start_all()
$machine->waitForFile("/etc/fish/generated_completions/kill.fish"); machine.wait_for_file("/etc/fish/generated_completions/coreutils.fish")
$machine->succeed("fish -ic 'echo \$fish_complete_path' | grep -q '/share/fish/completions /etc/fish/generated_completions /root/.local/share/fish/generated_completions\$'"); machine.wait_for_file("/etc/fish/generated_completions/kill.fish")
machine.succeed(
"fish -ic 'echo $fish_complete_path' | grep -q '/share/fish/completions /etc/fish/generated_completions /root/.local/share/fish/generated_completions$'"
)
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, lib, ... }: { import ./make-test-python.nix ({ pkgs, lib, ... }: {
name = "fluentd"; name = "fluentd";
machine = { pkgs, ... }: { machine = { pkgs, ... }: {
@ -33,14 +33,17 @@ import ./make-test.nix ({ pkgs, lib, ... }: {
inherit testMessage; inherit testMessage;
}); });
in '' in ''
$machine->start; machine.start()
$machine->waitForUnit('fluentd.service'); machine.wait_for_unit("fluentd.service")
$machine->waitForOpenPort(9880); machine.wait_for_open_port(9880)
$machine->succeed("curl -fsSL -X POST -H 'Content-type: application/json' -d @${payload} http://localhost:9880/test.tag"); machine.succeed(
"curl -fsSL -X POST -H 'Content-type: application/json' -d @${payload} http://localhost:9880/test.tag"
)
$machine->succeed("systemctl stop fluentd"); # blocking flush # blocking flush
machine.succeed("systemctl stop fluentd")
$machine->succeed("grep '${testMessage}' /tmp/current-log"); machine.succeed("grep '${testMessage}' /tmp/current-log")
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... }: import ./make-test-python.nix ({ pkgs, ... }:
let let
# Download Big Buck Bunny example, licensed under CC Attribution 3.0. # Download Big Buck Bunny example, licensed under CC Attribution 3.0.
testMkv = pkgs.fetchurl { testMkv = pkgs.fetchurl {
@ -19,7 +19,13 @@ in {
testScript = '' testScript = ''
# Test MP4 and MKV transcoding. Since this is a short clip, transcoding typically # Test MP4 and MKV transcoding. Since this is a short clip, transcoding typically
# only takes a few seconds. # only takes a few seconds.
$machine->succeed("HandBrakeCLI -i ${testMkv} -o test.mp4 -e x264 -q 20 -B 160"); start_all()
$machine->succeed("HandBrakeCLI -i ${testMkv} -o test.mkv -e x264 -q 20 -B 160");
machine.succeed(
"HandBrakeCLI -i ${testMkv} -o test.mp4 -e x264 -q 20 -B 160"
)
machine.succeed(
"HandBrakeCLI -i ${testMkv} -o test.mkv -e x264 -q 20 -B 160"
)
''; '';
}) })

View File

@ -1,6 +1,6 @@
# Test whether hibernation from partition works. # Test whether hibernation from partition works.
import ./make-test.nix (pkgs: { import ./make-test-python.nix (pkgs: {
name = "hibernate"; name = "hibernate";
nodes = { nodes = {
@ -28,16 +28,17 @@ import ./make-test.nix (pkgs: {
testScript = testScript =
'' ''
$machine->waitForUnit("multi-user.target"); machine.start()
$machine->succeed("mkswap /dev/vdb"); machine.wait_for_unit("multi-user.target")
$machine->succeed("swapon -a"); machine.succeed("mkswap /dev/vdb")
$machine->startJob("listener"); machine.succeed("swapon -a")
$machine->waitForOpenPort(4444); machine.start_job("listener")
$machine->succeed("systemctl hibernate &"); machine.wait_for_open_port(4444)
$machine->waitForShutdown; machine.succeed("systemctl hibernate &")
$probe->waitForUnit("multi-user.target"); machine.wait_for_shutdown()
$machine->start; probe.wait_for_unit("multi-user.target")
$probe->waitUntilSucceeds("echo test | nc machine 4444 -N"); machine.start()
probe.wait_until_succeeds("echo test | nc machine 4444 -N")
''; '';
}) })

View File

@ -1,5 +1,5 @@
# Test whether `houndd` indexes nixpkgs # Test whether `houndd` indexes nixpkgs
import ./make-test.nix ({ pkgs, ... } : { import ./make-test-python.nix ({ pkgs, ... } : {
name = "hound"; name = "hound";
meta = with pkgs.stdenv.lib.maintainers; { meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ grahamc ]; maintainers = [ grahamc ];
@ -46,13 +46,14 @@ import ./make-test.nix ({ pkgs, ... } : {
}; };
}; };
testScript = testScript = ''
'' startAll; start_all()
$machine->waitForUnit("network.target"); machine.wait_for_unit("network.target")
$machine->waitForUnit("hound.service"); machine.wait_for_unit("hound.service")
$machine->waitForOpenPort(6080); machine.wait_for_open_port(6080)
$machine->waitUntilSucceeds('curl http://127.0.0.1:6080/api/v1/search\?stats\=fosho\&repos\=\*\&rng=%3A20\&q\=hi\&files\=\&i=nope | grep "Filename" | grep "hello"'); machine.wait_until_succeeds(
"curl http://127.0.0.1:6080/api/v1/search\?stats\=fosho\&repos\=\*\&rng=%3A20\&q\=hi\&files\=\&i=nope | grep 'Filename' | grep 'hello'"
''; )
'';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... }: { import ./make-test-python.nix ({ pkgs, ... }: {
name = "icingaweb2"; name = "icingaweb2";
meta = with pkgs.stdenv.lib.maintainers; { meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ das_j ]; maintainers = [ das_j ];
@ -64,8 +64,8 @@ import ./make-test.nix ({ pkgs, ... }: {
}; };
testScript = '' testScript = ''
startAll(); start_all()
$icingaweb2->waitForUnit("multi-user.target"); icingaweb2.wait_for_unit("multi-user.target")
$icingaweb2->succeed("curl -sSf http://icingaweb2/authentication/login"); icingaweb2.succeed("curl -sSf http://icingaweb2/authentication/login")
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, lib, ... }: import ./make-test-python.nix ({ pkgs, lib, ... }:
{ {
name = "incron"; name = "incron";
@ -19,34 +19,34 @@ import ./make-test.nix ({ pkgs, lib, ... }:
}; };
testScript = '' testScript = ''
startAll; start_all()
$machine->waitForUnit("multi-user.target"); machine.wait_for_unit("multi-user.target")
$machine->waitForUnit("incron.service"); machine.wait_for_unit("incron.service")
$machine->succeed("test -d /test"); machine.succeed("test -d /test")
# create some activity for incron to monitor # create some activity for incron to monitor
$machine->succeed("touch /test/file"); machine.succeed("touch /test/file")
$machine->succeed("echo foo >> /test/file"); machine.succeed("echo foo >> /test/file")
$machine->succeed("mv /test/file /root"); machine.succeed("mv /test/file /root")
$machine->succeed("mv /root/file /test"); machine.succeed("mv /root/file /test")
$machine->sleep(1); machine.sleep(1)
# touch /test/file # touch /test/file
$machine->succeed("grep '/test/file IN_CREATE' /root/incron.log"); machine.succeed("grep '/test/file IN_CREATE' /root/incron.log")
# echo foo >> /test/file # echo foo >> /test/file
$machine->succeed("grep '/test/file IN_MODIFY' /root/incron.log"); machine.succeed("grep '/test/file IN_MODIFY' /root/incron.log")
$machine->succeed("grep '/test/file IN_CLOSE_WRITE' /root/incron.log"); machine.succeed("grep '/test/file IN_CLOSE_WRITE' /root/incron.log")
# mv /test/file /root # mv /test/file /root
$machine->succeed("grep '/test/file IN_MOVED_FROM' /root/incron.log"); machine.succeed("grep '/test/file IN_MOVED_FROM' /root/incron.log")
# mv /root/file /test # mv /root/file /test
$machine->succeed("grep '/test/file IN_MOVED_TO' /root/incron.log"); machine.succeed("grep '/test/file IN_MOVED_TO' /root/incron.log")
# ensure something unexpected is not present # ensure something unexpected is not present
$machine->fail("grep 'IN_OPEN' /root/incron.log"); machine.fail("grep 'IN_OPEN' /root/incron.log")
''; '';
}) })

View File

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

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... }: { import ./make-test-python.nix ({ pkgs, ... }: {
name = "minidlna"; name = "minidlna";
nodes = { nodes = {
@ -29,11 +29,11 @@ import ./make-test.nix ({ pkgs, ... }: {
testScript = testScript =
'' ''
startAll; start_all()
$server->succeed("mkdir -p /tmp/stuff && chown minidlna: /tmp/stuff"); server.succeed("mkdir -p /tmp/stuff && chown minidlna: /tmp/stuff")
$server->waitForUnit("minidlna"); server.wait_for_unit("minidlna")
$server->waitForOpenPort("8200"); server.wait_for_open_port("8200")
$server->succeed("curl --fail http://localhost:8200/"); server.succeed("curl --fail http://localhost:8200/")
$client->succeed("curl --fail http://server:8200/"); client.succeed("curl --fail http://server:8200/")
''; '';
}) })

View File

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, lib, ... }: import ./make-test-python.nix ({ pkgs, lib, ... }:
let let
port = 3142; port = 3142;
@ -37,16 +37,20 @@ with lib;
}; };
}; };
testScript = '' testScript = ''
startAll; start_all()
$default->waitForUnit('miniflux.service'); default.wait_for_unit("miniflux.service")
$default->waitForOpenPort(${toString defaultPort}); default.wait_for_open_port(${toString defaultPort})
$default->succeed("curl --fail 'http://localhost:${toString defaultPort}/healthcheck' | grep -q OK"); default.succeed("curl --fail 'http://localhost:${toString defaultPort}/healthcheck' | grep -q OK")
$default->succeed("curl 'http://localhost:${toString defaultPort}/v1/me' -u '${defaultUsername}:${defaultPassword}' -H Content-Type:application/json | grep -q '\"is_admin\":true'"); default.succeed(
"curl 'http://localhost:${toString defaultPort}/v1/me' -u '${defaultUsername}:${defaultPassword}' -H Content-Type:application/json | grep -q '\"is_admin\":true'"
)
$customized->waitForUnit('miniflux.service'); customized.wait_for_unit("miniflux.service")
$customized->waitForOpenPort(${toString port}); customized.wait_for_open_port(${toString port})
$customized->succeed("curl --fail 'http://localhost:${toString port}/healthcheck' | grep -q OK"); customized.succeed("curl --fail 'http://localhost:${toString port}/healthcheck' | grep -q OK")
$customized->succeed("curl 'http://localhost:${toString port}/v1/me' -u '${username}:${password}' -H Content-Type:application/json | grep -q '\"is_admin\":true'"); customized.succeed(
"curl 'http://localhost:${toString port}/v1/me' -u '${username}:${password}' -H Content-Type:application/json | grep -q '\"is_admin\":true'"
)
''; '';
}) })