about summary refs log tree commit diff
path: root/nixos/tests
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/tests')
-rw-r--r--nixos/tests/mediawiki.nix10
-rw-r--r--nixos/tests/openarena.nix15
-rw-r--r--nixos/tests/radicale.nix88
-rw-r--r--nixos/tests/xrdp.nix36
4 files changed, 87 insertions, 62 deletions
diff --git a/nixos/tests/mediawiki.nix b/nixos/tests/mediawiki.nix
index 6293e8a2f465..9468c1de8ccb 100644
--- a/nixos/tests/mediawiki.nix
+++ b/nixos/tests/mediawiki.nix
@@ -1,4 +1,4 @@
-import ./make-test.nix ({ pkgs, lib, ... }: {
+import ./make-test-python.nix ({ pkgs, lib, ... }: {
   name = "mediawiki";
   meta.maintainers = [ lib.maintainers.aanderse ];
 
@@ -11,9 +11,11 @@ import ./make-test.nix ({ pkgs, lib, ... }: {
     };
 
   testScript = ''
-    startAll;
+    start_all()
 
-    $machine->waitForUnit('phpfpm-mediawiki.service');
-    $machine->succeed('curl -L http://localhost/') =~ /MediaWiki has been installed/ or die;
+    machine.wait_for_unit("phpfpm-mediawiki.service")
+
+    page = machine.succeed("curl -L http://localhost/")
+    assert "MediaWiki has been installed" in page
   '';
 })
diff --git a/nixos/tests/openarena.nix b/nixos/tests/openarena.nix
index 4cc4db229637..b315426532ba 100644
--- a/nixos/tests/openarena.nix
+++ b/nixos/tests/openarena.nix
@@ -1,4 +1,4 @@
-import ./make-test.nix ({ pkgs, ...} : {
+import ./make-test-python.nix ({ pkgs, ...} : {
   name = "openarena";
   meta = with pkgs.stdenv.lib.maintainers; {
     maintainers = [ tomfitzhenry ];
@@ -23,14 +23,19 @@ import ./make-test.nix ({ pkgs, ...} : {
 
   testScript =
     ''
-      $machine->waitForUnit("openarena.service");
-      $machine->waitUntilSucceeds("ss --numeric --udp --listening | grep -q 27960");
+      machine.wait_for_unit("openarena.service")
+      machine.wait_until_succeeds("ss --numeric --udp --listening | grep -q 27960")
 
       # The log line containing 'resolve address' is last and only message that occurs after
       # the server starts accepting clients.
-      $machine->waitUntilSucceeds("journalctl -u openarena.service | grep 'resolve address: dpmaster.deathmask.net'");
+      machine.wait_until_succeeds(
+          "journalctl -u openarena.service | grep 'resolve address: dpmaster.deathmask.net'"
+      )
 
       # Check it's possible to join the server.
-      $machine->succeed("echo -n -e '\\xff\\xff\\xff\\xffgetchallenge' | socat - UDP4-DATAGRAM:127.0.0.1:27960 | grep -q challengeResponse");
+      # Can't use substring match instead of grep because the output is not utf-8
+      machine.succeed(
+          "echo -n -e '\\xff\\xff\\xff\\xffgetchallenge' | socat - UDP4-DATAGRAM:127.0.0.1:27960 | grep -q challengeResponse"
+      )
     '';
 })
diff --git a/nixos/tests/radicale.nix b/nixos/tests/radicale.nix
index 607964255640..c81e78a8f994 100644
--- a/nixos/tests/radicale.nix
+++ b/nixos/tests/radicale.nix
@@ -28,7 +28,7 @@ let
 
 in
 
-  import ./make-test.nix ({ lib, ... }@args: {
+  import ./make-test-python.nix ({ lib, ... }@args: {
     name = "radicale";
     meta.maintainers = with lib.maintainers; [ aneeshusa infinisil ];
 
@@ -64,43 +64,59 @@ in
         newSystem = nodes.${nodeName}.config.system.build.toplevel;
       in "${newSystem}/bin/switch-to-configuration test";
     in ''
-      # Check Radicale 1 functionality
-      $radicale->succeed('${switchToConfig "radicale1"} >&2');
-      $radicale->waitForUnit('radicale.service');
-      $radicale->waitForOpenPort(${port});
-      $radicale->succeed('curl --fail http://${user}:${password}@localhost:${port}/someuser/calendar.ics/');
+      with subtest("Check Radicale 1 functionality"):
+          radicale.succeed(
+              "${switchToConfig "radicale1"} >&2"
+          )
+          radicale.wait_for_unit("radicale.service")
+          radicale.wait_for_open_port(${port})
+          radicale.succeed(
+              "curl --fail http://${user}:${password}@localhost:${port}/someuser/calendar.ics/"
+          )
 
-      # Export data in Radicale 2 format
-      $radicale->succeed('systemctl stop radicale');
-      $radicale->succeed('ls -al /tmp/collections');
-      $radicale->fail('ls -al /tmp/collections-new');
-      # Radicale exits immediately after exporting storage
-      $radicale->succeed('${switchToConfig "radicale1_export"} >&2');
-      $radicale->waitUntilFails('systemctl status radicale');
-      $radicale->succeed('ls -al /tmp/collections');
-      $radicale->succeed('ls -al /tmp/collections-new');
+      with subtest("Export data in Radicale 2 format"):
+          radicale.succeed("systemctl stop radicale")
+          radicale.succeed("ls -al /tmp/collections")
+          radicale.fail("ls -al /tmp/collections-new")
 
-      # Verify data in Radicale 2 format
-      $radicale->succeed('rm -r /tmp/collections/${user}');
-      $radicale->succeed('mv /tmp/collections-new/collection-root /tmp/collections');
-      $radicale->succeed('${switchToConfig "radicale2_verify"} >&2');
-      $radicale->waitUntilFails('systemctl status radicale');
-      my ($retcode, $logs) = $radicale->execute('journalctl -u radicale -n 10');
-      if ($retcode != 0 || index($logs, 'Verifying storage') == -1) {
-        die "Radicale 2 didn't verify storage"
-      }
-      if (index($logs, 'failed') != -1 || index($logs, 'exception') != -1) {
-        die "storage verification failed"
-      }
+      with subtest("Radicale exits immediately after exporting storage"):
+          radicale.succeed(
+              "${switchToConfig "radicale1_export"} >&2"
+          )
+          radicale.wait_until_fails("systemctl status radicale")
+          radicale.succeed("ls -al /tmp/collections")
+          radicale.succeed("ls -al /tmp/collections-new")
 
-      # Check Radicale 2 functionality
-      $radicale->succeed('${switchToConfig "radicale2"} >&2');
-      $radicale->waitForUnit('radicale.service');
-      $radicale->waitForOpenPort(${port});
-      my ($retcode, $output) = $radicale->execute('curl --fail http://${user}:${password}@localhost:${port}/someuser/calendar.ics/');
-      if ($retcode != 0 || index($output, 'VCALENDAR') == -1) {
-        die "Could not read calendar from Radicale 2"
-      }
-      $radicale->succeed('curl --fail http://${user}:${password}@localhost:${port}/.web/');
+      with subtest("Verify data in Radicale 2 format"):
+          radicale.succeed("rm -r /tmp/collections/${user}")
+          radicale.succeed("mv /tmp/collections-new/collection-root /tmp/collections")
+          radicale.succeed(
+              "${switchToConfig "radicale2_verify"} >&2"
+          )
+          radicale.wait_until_fails("systemctl status radicale")
+
+          (retcode, logs) = radicale.execute("journalctl -u radicale -n 10")
+          assert (
+              retcode == 0 and "Verifying storage" in logs
+          ), "Radicale 2 didn't verify storage"
+          assert (
+              "failed" not in logs and "exception" not in logs
+          ), "storage verification failed"
+
+      with subtest("Check Radicale 2 functionality"):
+          radicale.succeed(
+              "${switchToConfig "radicale2"} >&2"
+          )
+          radicale.wait_for_unit("radicale.service")
+          radicale.wait_for_open_port(${port})
+
+          (retcode, output) = radicale.execute(
+              "curl --fail http://${user}:${password}@localhost:${port}/someuser/calendar.ics/"
+          )
+          assert (
+              retcode == 0 and "VCALENDAR" in output
+          ), "Could not read calendar from Radicale 2"
+
+      radicale.succeed("curl --fail http://${user}:${password}@localhost:${port}/.web/")
     '';
 })
diff --git a/nixos/tests/xrdp.nix b/nixos/tests/xrdp.nix
index 0106aefe8318..1aceeffb955d 100644
--- a/nixos/tests/xrdp.nix
+++ b/nixos/tests/xrdp.nix
@@ -1,4 +1,4 @@
-import ./make-test.nix ({ pkgs, ...} : {
+import ./make-test-python.nix ({ pkgs, ...} : {
   name = "xrdp";
   meta = with pkgs.stdenv.lib.maintainers; {
     maintainers = [ volth ];
@@ -21,25 +21,27 @@ import ./make-test.nix ({ pkgs, ...} : {
     };
   };
 
-  testScript = { ... }: ''
-    startAll;
+  testScript = { nodes, ... }: let
+    user = nodes.client.config.users.users.alice;
+  in ''
+    start_all()
 
-    $client->waitForX;
-    $client->waitForFile("/home/alice/.Xauthority");
-    $client->succeed("xauth merge ~alice/.Xauthority");
+    client.wait_for_x()
+    client.wait_for_file("${user.home}/.Xauthority")
+    client.succeed("xauth merge ${user.home}/.Xauthority")
 
-    $client->sleep(5);
+    client.sleep(5)
 
-    $client->execute("xterm &");
-    $client->sleep(1);
-    $client->sendChars("xfreerdp /cert-tofu /w:640 /h:480 /v:127.0.0.1 /u:alice /p:foobar\n");
-    $client->sleep(5);
-    $client->screenshot("localrdp");
+    client.execute("xterm &")
+    client.sleep(1)
+    client.send_chars("xfreerdp /cert-tofu /w:640 /h:480 /v:127.0.0.1 /u:${user.name} /p:${user.password}\n")
+    client.sleep(5)
+    client.screenshot("localrdp")
 
-    $client->execute("xterm &");
-    $client->sleep(1);
-    $client->sendChars("xfreerdp /cert-tofu /w:640 /h:480 /v:server /u:alice /p:foobar\n");
-    $client->sleep(5);
-    $client->screenshot("remoterdp");
+    client.execute("xterm &")
+    client.sleep(1)
+    client.send_chars("xfreerdp /cert-tofu /w:640 /h:480 /v:server /u:${user.name} /p:${user.password}\n")
+    client.sleep(5)
+    client.screenshot("remoterdp")
   '';
 })