1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-20 12:42:24 +00:00

Merge pull request #75701 from kampka/port-tests-2

Port NixOS tests to python
This commit is contained in:
Dmitry Kalinkin 2019-12-17 21:51:42 -05:00 committed by GitHub
commit 9faa37cfdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 81 additions and 67 deletions

View file

@ -1,4 +1,4 @@
import ./make-test.nix ({ lib, ... } : { import ./make-test-python.nix ({ lib, ... } : {
name = "paperless"; name = "paperless";
meta = with lib.maintainers; { meta = with lib.maintainers; {
maintainers = [ earvstedt ]; maintainers = [ earvstedt ];
@ -13,17 +13,24 @@ import ./make-test.nix ({ lib, ... } : {
}; };
testScript = '' testScript = ''
$machine->waitForUnit("paperless-consumer.service"); machine.wait_for_unit("paperless-consumer.service")
# Create test doc
$machine->succeed('convert -size 400x40 xc:white -font "DejaVu-Sans" -pointsize 20 -fill black \
-annotate +5+20 "hello world 16-10-2005" /var/lib/paperless/consume/doc.png');
$machine->waitForUnit("paperless-server.service"); # Create test doc
# Wait until server accepts connections machine.succeed(
$machine->waitUntilSucceeds("curl -s localhost:28981"); "convert -size 400x40 xc:white -font 'DejaVu-Sans' -pointsize 20 -fill black -annotate +5+20 'hello world 16-10-2005' /var/lib/paperless/consume/doc.png"
# Wait until document is consumed )
$machine->waitUntilSucceeds('(($(curl -s localhost:28981/api/documents/ | jq .count) == 1))');
$machine->succeed("curl -s localhost:28981/api/documents/ | jq '.results | .[0] | .created'") with subtest("Service gets ready"):
=~ /2005-10-16/ or die; machine.wait_for_unit("paperless-server.service")
# Wait until server accepts connections
machine.wait_until_succeeds("curl -s localhost:28981")
with subtest("Test document is consumed"):
machine.wait_until_succeeds(
"(($(curl -s localhost:28981/api/documents/ | jq .count) == 1))"
)
assert "2005-10-16" in machine.succeed(
"curl -s localhost:28981/api/documents/ | jq '.results | .[0] | .created'"
)
''; '';
}) })

View file

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... }: { import ./make-test-python.nix ({ pkgs, ... }: {
name = "powerdns"; name = "powerdns";
nodes.server = { ... }: { nodes.server = { ... }: {
@ -6,7 +6,7 @@ import ./make-test.nix ({ pkgs, ... }: {
}; };
testScript = '' testScript = ''
$server->waitForUnit("pdns-recursor"); server.wait_for_unit("pdns-recursor")
$server->waitForOpenPort("53"); server.wait_for_open_port("53")
''; '';
}) })

View file

@ -1,6 +1,6 @@
# This test runs peerflix and checks if peerflix starts # This test runs peerflix and checks if peerflix starts
import ./make-test.nix ({ pkgs, ...} : { import ./make-test-python.nix ({ pkgs, ...} : {
name = "peerflix"; name = "peerflix";
meta = with pkgs.stdenv.lib.maintainers; { meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ offline ]; maintainers = [ offline ];
@ -15,9 +15,9 @@ import ./make-test.nix ({ pkgs, ...} : {
}; };
testScript = '' testScript = ''
startAll; start_all()
$peerflix->waitForUnit("peerflix.service"); peerflix.wait_for_unit("peerflix.service")
$peerflix->waitUntilSucceeds("curl localhost:9000"); peerflix.wait_until_succeeds("curl localhost:9000")
''; '';
}) })

View file

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ... } : import ./make-test-python.nix ({ pkgs, ... } :
let let
role = "test"; role = "test";
password = "secret"; password = "secret";
@ -29,11 +29,13 @@ in
}; };
testScript = '' testScript = ''
startAll; start_all()
$one->waitForUnit("default.target"); one.wait_for_unit("default.target")
$one->requireActiveUnit("pgmanage.service"); one.require_unit_state("pgmanage.service", "active")
# Test if we can log in. # Test if we can log in.
$one->waitUntilSucceeds("curl 'http://localhost:8080/pgmanage/auth' --data 'action=login&connname=${conn}&username=${role}&password=${password}' --fail"); one.wait_until_succeeds(
"curl 'http://localhost:8080/pgmanage/auth' --data 'action=login&connname=${conn}&username=${role}&password=${password}' --fail"
)
''; '';
}) })

View file

@ -1,7 +1,7 @@
let testString = "can-use-subgroups"; in let testString = "can-use-subgroups"; in
import ./make-test.nix ({ ...}: { import ./make-test-python.nix ({ ...}: {
name = "php-httpd-pcre-jit-test"; name = "php-httpd-pcre-jit-test";
machine = { lib, pkgs, ... }: { machine = { lib, pkgs, ... }: {
time.timeZone = "UTC"; time.timeZone = "UTC";
@ -31,9 +31,10 @@ import ./make-test.nix ({ ...}: {
}; };
testScript = { ... }: testScript = { ... }:
'' ''
$machine->waitForUnit('httpd.service'); machine.wait_for_unit("httpd.service")
# Ensure php evaluation by matching on the var_dump syntax # Ensure php evaluation by matching on the var_dump syntax
$machine->succeed('curl -vvv -s http://127.0.0.1:80/index.php \ assert 'string(${toString (builtins.stringLength testString)}) "${testString}"' in machine.succeed(
| grep "string(${toString (builtins.stringLength testString)}) \"${testString}\""'); "curl -vvv -s http://127.0.0.1:80/index.php"
)
''; '';
}) })

View file

@ -1,4 +1,4 @@
import ./make-test.nix ({ pkgs, ...} : { import ./make-test-python.nix ({ pkgs, ...} : {
name = "postgis"; name = "postgis";
meta = with pkgs.stdenv.lib.maintainers; { meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ lsix ]; maintainers = [ lsix ];
@ -20,10 +20,10 @@ import ./make-test.nix ({ pkgs, ...} : {
}; };
testScript = '' testScript = ''
startAll; start_all()
$master->waitForUnit("postgresql"); master.wait_for_unit("postgresql")
$master->sleep(10); # Hopefully this is long enough!! master.sleep(10) # Hopefully this is long enough!!
$master->succeed("sudo -u postgres psql -c 'CREATE EXTENSION postgis;'"); master.succeed("sudo -u postgres psql -c 'CREATE EXTENSION postgis;'")
$master->succeed("sudo -u postgres psql -c 'CREATE EXTENSION postgis_topology;'"); master.succeed("sudo -u postgres psql -c 'CREATE EXTENSION postgis_topology;'")
''; '';
}) })

View file

@ -5,7 +5,7 @@
# #
# All interfaces are in OSPF Area 0. # All interfaces are in OSPF Area 0.
import ./make-test.nix ({ pkgs, ... }: import ./make-test-python.nix ({ pkgs, ... }:
let let
ifAddr = node: iface: (pkgs.lib.head node.config.networking.interfaces.${iface}.ipv4.addresses).address; ifAddr = node: iface: (pkgs.lib.head node.config.networking.interfaces.${iface}.ipv4.addresses).address;
@ -74,23 +74,23 @@ import ./make-test.nix ({ pkgs, ... }:
testScript = testScript =
{ ... }: { ... }:
'' ''
startAll; start_all()
# Wait for the networking to start on all machines # Wait for the networking to start on all machines
$_->waitForUnit("network.target") foreach values %vms; for machine in client, router1, router2, server:
machine.wait_for_unit("network.target")
# Wait for OSPF to form adjacencies with subtest("Wait for OSPF to form adjacencies"):
for my $gw ($router1, $router2) { for gw in router1, router2:
$gw->waitForUnit("ospfd"); gw.wait_for_unit("ospfd")
$gw->waitUntilSucceeds("vtysh -c 'show ip ospf neighbor' | grep Full"); gw.wait_until_succeeds("vtysh -c 'show ip ospf neighbor' | grep Full")
$gw->waitUntilSucceeds("vtysh -c 'show ip route' | grep '^O>'"); gw.wait_until_succeeds("vtysh -c 'show ip route' | grep '^O>'")
}
# Test ICMP. with subtest("Test ICMP"):
$client->succeed("ping -c 3 server >&2"); client.wait_until_succeeds("ping -c 3 server >&2")
# Test whether HTTP works. with subtest("Test whether HTTP works"):
$server->waitForUnit("httpd"); server.wait_for_unit("httpd")
$client->succeed("curl --fail http://server/ >&2"); client.succeed("curl --fail http://server/ >&2")
''; '';
}) })

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.sonarr.enable = true; }; { services.sonarr.enable = true; };
testScript = '' testScript = ''
$machine->waitForUnit('sonarr.service'); machine.wait_for_unit("sonarr.service")
$machine->waitForOpenPort('8989'); machine.wait_for_open_port("8989")
$machine->succeed("curl --fail http://localhost:8989/"); machine.succeed("curl --fail http://localhost:8989/")
''; '';
}) })

View file

@ -1,6 +1,6 @@
# Test configuration switching. # Test configuration switching.
import ./make-test.nix ({ pkgs, ...} : { import ./make-test-python.nix ({ pkgs, ...} : {
name = "switch-test"; name = "switch-test";
meta = with pkgs.stdenv.lib.maintainers; { meta = with pkgs.stdenv.lib.maintainers; {
maintainers = [ gleber ]; maintainers = [ gleber ];
@ -28,7 +28,11 @@ import ./make-test.nix ({ pkgs, ...} : {
exec env -i "$@" | tee /dev/stderr exec env -i "$@" | tee /dev/stderr
''; '';
in '' in ''
$machine->succeed("${stderrRunner} ${originalSystem}/bin/switch-to-configuration test"); machine.succeed(
$machine->succeed("${stderrRunner} ${otherSystem}/bin/switch-to-configuration test"); "${stderrRunner} ${originalSystem}/bin/switch-to-configuration test"
)
machine.succeed(
"${stderrRunner} ${otherSystem}/bin/switch-to-configuration test"
)
''; '';
}) })

View file

@ -1,7 +1,7 @@
# Regression test for systemd-timesync having moved the state directory without # Regression test for systemd-timesync having moved the state directory without
# upstream providing a migration path. https://github.com/systemd/systemd/issues/12131 # upstream providing a migration path. https://github.com/systemd/systemd/issues/12131
import ./make-test.nix (let import ./make-test-python.nix (let
common = { lib, ... }: { common = { lib, ... }: {
# override the `false` value from the qemu-vm base profile # override the `false` value from the qemu-vm base profile
services.timesyncd.enable = lib.mkForce true; services.timesyncd.enable = lib.mkForce true;
@ -25,28 +25,28 @@ in {
}; };
testScript = '' testScript = ''
startAll; start_all()
$current->succeed('systemctl status systemd-timesyncd.service'); current.succeed("systemctl status systemd-timesyncd.service")
# on a new install with a recent systemd there should not be any # on a new install with a recent systemd there should not be any
# leftovers from the dynamic user mess # leftovers from the dynamic user mess
$current->succeed('test -e /var/lib/systemd/timesync'); current.succeed("test -e /var/lib/systemd/timesync")
$current->succeed('test ! -L /var/lib/systemd/timesync'); current.succeed("test ! -L /var/lib/systemd/timesync")
# timesyncd should be running on the upgrading system since we fixed the # timesyncd should be running on the upgrading system since we fixed the
# file bits in the activation script # file bits in the activation script
$pre1909->succeed('systemctl status systemd-timesyncd.service'); pre1909.succeed("systemctl status systemd-timesyncd.service")
# the path should be gone after the migration # the path should be gone after the migration
$pre1909->succeed('test ! -e /var/lib/private/systemd/timesync'); pre1909.succeed("test ! -e /var/lib/private/systemd/timesync")
# and the new path should no longer be a symlink # and the new path should no longer be a symlink
$pre1909->succeed('test -e /var/lib/systemd/timesync'); pre1909.succeed("test -e /var/lib/systemd/timesync")
$pre1909->succeed('test ! -L /var/lib/systemd/timesync'); pre1909.succeed("test ! -L /var/lib/systemd/timesync")
# after a restart things should still work and not fail in the activation # after a restart things should still work and not fail in the activation
# scripts and cause the boot to fail.. # scripts and cause the boot to fail..
$pre1909->shutdown; pre1909.shutdown()
$pre1909->start; pre1909.start()
$pre1909->succeed('systemctl status systemd-timesyncd.service'); pre1909.succeed("systemctl status systemd-timesyncd.service")
''; '';
}) })