summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Weiss <dev.primeos@gmail.com>2022-02-04 22:13:44 +0100
committerGitHub <noreply@github.com>2022-02-04 22:13:44 +0100
commit1c4d0f130b0536b68b33d3132314c9985375233c (patch)
tree4ebbb80c659dc10cac0d7b26d759add00ac8ebaf
parent61326af4a8ef46ca385a84523257bca6b3c15dd3 (diff)
parentabcf236f3644451be466dfea7c4605f27af15d1d (diff)
downloadnixpkgs-1c4d0f130b0536b68b33d3132314c9985375233c.tar
nixpkgs-1c4d0f130b0536b68b33d3132314c9985375233c.tar.gz
nixpkgs-1c4d0f130b0536b68b33d3132314c9985375233c.tar.bz2
nixpkgs-1c4d0f130b0536b68b33d3132314c9985375233c.tar.lz
nixpkgs-1c4d0f130b0536b68b33d3132314c9985375233c.tar.xz
nixpkgs-1c4d0f130b0536b68b33d3132314c9985375233c.tar.zst
nixpkgs-1c4d0f130b0536b68b33d3132314c9985375233c.zip
Merge pull request #158027 from Synthetica9/test-sway-swaylock
nixosTests.sway: add swaylock test
-rw-r--r--nixos/tests/sway.nix29
1 files changed, 19 insertions, 10 deletions
diff --git a/nixos/tests/sway.nix b/nixos/tests/sway.nix
index 43b8c847304..1e9e146c4b6 100644
--- a/nixos/tests/sway.nix
+++ b/nixos/tests/sway.nix
@@ -1,6 +1,4 @@
-import ./make-test-python.nix ({ pkgs, lib, ... }:
-
-{
+import ./make-test-python.nix ({ pkgs, lib, ... }: {
   name = "sway";
   meta = {
     maintainers = with lib.maintainers; [ primeos synthetica ];
@@ -70,6 +68,14 @@ import ./make-test-python.nix ({ pkgs, lib, ... }:
   enableOCR = true;
 
   testScript = { nodes, ... }: ''
+    import shlex
+
+    def swaymsg(command: str, succeed=True):
+        with machine.nested(f"sending swaymsg {command!r}" + " (allowed to fail)" * (not succeed)):
+          (machine.succeed if succeed else machine.execute)(
+            f"su - alice -c {shlex.quote('swaymsg -- ' + command)}"
+          )
+
     start_all()
     machine.wait_for_unit("multi-user.target")
 
@@ -81,9 +87,7 @@ import ./make-test-python.nix ({ pkgs, lib, ... }:
     machine.wait_for_file("/tmp/sway-ipc.sock")
 
     # Test XWayland (foot does not support X):
-    machine.succeed(
-        "su - alice -c 'swaymsg exec WINIT_UNIX_BACKEND=x11 WAYLAND_DISPLAY=invalid alacritty'"
-    )
+    swaymsg("exec WINIT_UNIX_BACKEND=x11 WAYLAND_DISPLAY=invalid alacritty")
     machine.wait_for_text("alice@machine")
     machine.send_chars("test-x11\n")
     machine.wait_for_file("/tmp/test-x11-exit-ok")
@@ -107,9 +111,7 @@ import ./make-test-python.nix ({ pkgs, lib, ... }:
 
     # Test gpg-agent starting pinentry-gnome3 via D-Bus (tests if
     # $WAYLAND_DISPLAY is correctly imported into the D-Bus user env):
-    machine.succeed(
-        "su - alice -c 'swaymsg -- exec gpg --no-tty --yes --quick-generate-key test'"
-    )
+    swaymsg("exec gpg --no-tty --yes --quick-generate-key test")
     machine.wait_until_succeeds("pgrep --exact gpg")
     machine.wait_for_text("Passphrase")
     machine.screenshot("gpg_pinentry")
@@ -121,8 +123,15 @@ import ./make-test-python.nix ({ pkgs, lib, ... }:
     machine.wait_for_text("You pressed the exit shortcut.")
     machine.screenshot("sway_exit")
 
+    swaymsg("exec swaylock")
+    machine.wait_until_succeeds("pgrep -x swaylock")
+    machine.sleep(3)
+    machine.send_chars("${nodes.machine.config.users.users.alice.password}")
+    machine.send_key("ret")
+    machine.wait_until_fails("pgrep -x swaylock")
+
     # Exit Sway and verify process exit status 0:
-    machine.succeed("su - alice -c 'swaymsg exit || true'")
+    swaymsg("exit", succeed=False)
     machine.wait_until_fails("pgrep -x sway")
     machine.wait_for_file("/tmp/sway-exit-ok")
   '';