From 6ebf14143aee10d8a62eb660bb56ebed3ed674e2 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 24 Mar 2019 15:52:30 +0100 Subject: [PATCH] systemd: add some basic tests --- tests/default.nix | 13 ++++---- tests/modules/systemd/default.nix | 4 +++ tests/modules/systemd/services-expected.conf | 5 ++++ tests/modules/systemd/services.nix | 23 +++++++++++++++ tests/modules/systemd/timers-expected.conf | 8 +++++ tests/modules/systemd/timers.nix | 31 ++++++++++++++++++++ 6 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 tests/modules/systemd/default.nix create mode 100644 tests/modules/systemd/services-expected.conf create mode 100644 tests/modules/systemd/services.nix create mode 100644 tests/modules/systemd/timers-expected.conf create mode 100644 tests/modules/systemd/timers.nix diff --git a/tests/default.nix b/tests/default.nix index cf1226d2e..2a0e53388 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -27,9 +27,12 @@ import nmt { texlive-minimal = ./modules/programs/texlive-minimal.nix; xresources = ./modules/xresources.nix; } - // pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux { - i3-keybindings = ./modules/services/window-managers/i3-keybindings.nix; - } - // import ./modules/programs/tmux - // import ./modules/programs/ssh; + // pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux ( + { + i3-keybindings = ./modules/services/window-managers/i3-keybindings.nix; + } + // import ./modules/systemd + ) + // import ./modules/programs/ssh + // import ./modules/programs/tmux; } diff --git a/tests/modules/systemd/default.nix b/tests/modules/systemd/default.nix new file mode 100644 index 000000000..cc1d5b6ba --- /dev/null +++ b/tests/modules/systemd/default.nix @@ -0,0 +1,4 @@ +{ + systemd-services = ./services.nix; + systemd-timers = ./timers.nix; +} diff --git a/tests/modules/systemd/services-expected.conf b/tests/modules/systemd/services-expected.conf new file mode 100644 index 000000000..34b9618d6 --- /dev/null +++ b/tests/modules/systemd/services-expected.conf @@ -0,0 +1,5 @@ +[Service] +ExecStart=/some/exec/start/command --with-arguments "%i" + +[Unit] +Description=A basic test service diff --git a/tests/modules/systemd/services.nix b/tests/modules/systemd/services.nix new file mode 100644 index 000000000..f1f7a42bb --- /dev/null +++ b/tests/modules/systemd/services.nix @@ -0,0 +1,23 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + systemd.user.services."test-service@" = { + Unit = { + Description = "A basic test service"; + }; + + Service = { + ExecStart = ''/some/exec/start/command --with-arguments "%i"''; + }; + }; + + nmt.script = '' + local serviceFile=home-files/.config/systemd/user/test-service@.service + assertFileExists $serviceFile + assertFileContent $serviceFile ${./services-expected.conf} + ''; + }; +} diff --git a/tests/modules/systemd/timers-expected.conf b/tests/modules/systemd/timers-expected.conf new file mode 100644 index 000000000..b19f044cc --- /dev/null +++ b/tests/modules/systemd/timers-expected.conf @@ -0,0 +1,8 @@ +[Install] +WantedBy=timers.target + +[Timer] +OnUnitActiveSec=1h 30m + +[Unit] +Description=A basic test timer diff --git a/tests/modules/systemd/timers.nix b/tests/modules/systemd/timers.nix new file mode 100644 index 000000000..0fa0070cd --- /dev/null +++ b/tests/modules/systemd/timers.nix @@ -0,0 +1,31 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + systemd.user.timers.test-timer = { + Unit = { + Description = "A basic test timer"; + }; + + Timer = { + OnUnitActiveSec = "1h 30m"; + }; + + Install = { + WantedBy = [ "timers.target" ]; + }; + }; + + nmt.script = '' + local unitDir=home-files/.config/systemd/user + local timerFile=$unitDir/test-timer.timer + + assertFileExists $timerFile + assertFileContent $timerFile ${./timers-expected.conf} + + assertFileExists $unitDir/timers.target.wants/test-timer.timer + ''; + }; +}