From 2656b8db1909d72a7eb4e3a7ae1634eb8170af9e Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Mon, 24 Nov 2025 16:19:25 -0500 Subject: [PATCH] zfs: expand testing to include a failing multi case --- tests/zfs.nix | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/zfs.nix b/tests/zfs.nix index 7d3c746..d14bb55 100644 --- a/tests/zfs.nix +++ b/tests/zfs.nix @@ -25,6 +25,11 @@ testPkgs.testers.runNixOSTest { # Test multi-command logic: service with multiple serviceMountWithZpool calls (lib.serviceMountWithZpool "multi-service" "rpool" [ "/mnt/rpool_data" ]) (lib.serviceMountWithZpool "multi-service" "rpool2" [ "/mnt/rpool2_data" ]) + + # Test multi-command logic: service with multiple serviceMountWithZpool calls + # BUT this one should fail as `/mnt/rpool_moar_data` is not on rpool2 + (lib.serviceMountWithZpool "multi-service-fail" "rpool" [ "/mnt/rpool_data" ]) + (lib.serviceMountWithZpool "multi-service-fail" "rpool2" [ "/mnt/rpool_moar_data" ]) ]; virtualisation = { @@ -68,6 +73,14 @@ testPkgs.testers.runNixOSTest { ExecStart = lib.getExe pkgs.bash; }; }; + + systemd.services."multi-service-fail" = { + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + ExecStart = lib.getExe pkgs.bash; + }; + }; }; testScript = '' @@ -92,6 +105,8 @@ testPkgs.testers.runNixOSTest { machine.succeed("zfs create -o mountpoint=/mnt/rpool2_data rpool2/data") + machine.succeed("zfs create -o mountpoint=/mnt/rpool_moar_data rpool/moar_data") + # Test that valid service starts successfully machine.succeed("systemctl start test-service") @@ -117,6 +132,21 @@ testPkgs.testers.runNixOSTest { assert "Expected pool: rpool2" in journal_output assert "Actual pool: rpool" in journal_output + + # Test that invalid-service mount service fails validation + machine.fail("systemctl start multi-service-fail.service") + + # Check the journal for our detailed validation error message + journal_output = machine.succeed("journalctl -u multi-service-fail-mounts.service --no-pager") + print("JOURNAL OUTPUT:") + print(journal_output) + + # Verify our validation error is in the journal using Python string matching + assert "ERROR: ZFS pool mismatch for /mnt/rpool_moar_data" in journal_output, "no zfs pool mismatch found (1)" + assert "Expected pool: rpool2" in journal_output, "no zfs pool mismatch found (2)" + assert "Actual pool: rpool" in journal_output, "no zfs pool mismatch found (3)" + + machine.succeed("systemctl start multi-service") machine.succeed("systemctl is-active multi-service-mounts.service") '';