1
Fork 0
mirror of https://github.com/RGBCube/hjem synced 2025-10-15 14:12:22 +00:00

modules/xdg: overhaul tests

This commit is contained in:
lunarnovaa 2025-07-29 13:38:21 -07:00
parent 5c81ae5840
commit a4c1bff70a
No known key found for this signature in database
2 changed files with 41 additions and 26 deletions

View file

@ -12,6 +12,7 @@ in
... ...
}: let }: let
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.strings) optionalString;
xdg = { xdg = {
clobber, clobber,
@ -21,7 +22,7 @@ in
directory = mkIf altLocation (userHome + "/customCacheDirectory"); directory = mkIf altLocation (userHome + "/customCacheDirectory");
files = { files = {
"foo" = { "foo" = {
text = "Hello world!"; text = "Hello ${optionalString clobber "new "}world!";
inherit clobber; inherit clobber;
}; };
}; };
@ -31,7 +32,7 @@ in
files = { files = {
"bar.json" = { "bar.json" = {
generator = lib.generators.toJSON {}; generator = lib.generators.toJSON {};
value = {bar = true;}; value = {bar = "Hello ${optionalString clobber "new "}second world!";};
inherit clobber; inherit clobber;
}; };
}; };
@ -41,7 +42,7 @@ in
files = { files = {
"baz.toml" = { "baz.toml" = {
generator = (pkgs.formats.toml {}).generate "baz.toml"; generator = (pkgs.formats.toml {}).generate "baz.toml";
value = {baz = true;}; value = {baz = "Hello ${optionalString clobber "new "}third world!";};
inherit clobber; inherit clobber;
}; };
}; };
@ -50,7 +51,7 @@ in
directory = mkIf altLocation (userHome + "/customStateDirectory"); directory = mkIf altLocation (userHome + "/customStateDirectory");
files = { files = {
"foo" = { "foo" = {
source = pkgs.writeText "file-bar" "Hello World!"; source = pkgs.writeText "file-bar" "Hello ${optionalString clobber "new "}fourth world!";
inherit clobber; inherit clobber;
}; };
}; };
@ -95,7 +96,6 @@ in
}; };
}; };
}; };
altFilesGetOverwritten.configuration = { altFilesGetOverwritten.configuration = {
hjem.users.alice = { hjem.users.alice = {
files.".config/foo" = { files.".config/foo" = {
@ -123,28 +123,41 @@ in
with subtest("Default file locations get liked"): with subtest("Default file locations get liked"):
node1.succeed("${specialisations}/defaultFilesGetLinked/bin/switch-to-configuration test") node1.succeed("${specialisations}/defaultFilesGetLinked/bin/switch-to-configuration test")
node1.succeed("test -L ${userHome}/.cache/foo") node1.succeed("test -L ${userHome}/.cache/foo")
node1.succeed("grep \"Hello world!\" ~alice/.cache/foo")
node1.succeed("test -L ${userHome}/.config/bar.json") node1.succeed("test -L ${userHome}/.config/bar.json")
node1.succeed("grep \"Hello second world!\" ~alice/.config/bar.json")
node1.succeed("test -L ${userHome}/.local/share/baz.toml") node1.succeed("test -L ${userHome}/.local/share/baz.toml")
node1.succeed("grep \"Hello third world!\" ~alice/.local/share/baz.toml")
node1.succeed("test -L ${userHome}/.local/state/foo") node1.succeed("test -L ${userHome}/.local/state/foo")
node1.succeed("grep \"Hello fourth world!\" ~alice/.local/state/foo")
with subtest("Alternate file locations get linked"): with subtest("Alternate file locations get linked"):
node1.succeed("${specialisations}/altFilesGetLinked/bin/switch-to-configuration test") node1.succeed("${specialisations}/altFilesGetLinked/bin/switch-to-configuration test")
node1.succeed("test -L ${userHome}/customCacheDirectory/foo") node1.succeed("test -L ${userHome}/customCacheDirectory/foo")
node1.succeed("grep \"Hello world!\" ~alice/customCacheDirectory/foo")
node1.succeed("test -L ${userHome}/customConfigDirectory/bar.json") node1.succeed("test -L ${userHome}/customConfigDirectory/bar.json")
node1.succeed("grep \"Hello second world!\" ~alice/customConfigDirectory/bar.json")
node1.succeed("test -L ${userHome}/customDataDirectory/baz.toml") node1.succeed("test -L ${userHome}/customDataDirectory/baz.toml")
node1.succeed("grep \"Hello third world!\" ~alice/customDataDirectory/baz.toml")
node1.succeed("test -L ${userHome}/customStateDirectory/foo") node1.succeed("test -L ${userHome}/customStateDirectory/foo")
node1.succeed("grep \"Hello fourth world!\" ~alice/customStateDirectory/foo")
# Same name as config test file to verify proper merging # Same name as config test file to verify proper merging
node1.succeed("test -L ${userHome}/.config/foo") node1.succeed("test -L ${userHome}/.config/foo")
node1.succeed("grep \"Hello world!\" ${userHome}/.config/foo") node1.succeed("grep \"Hello world!\" ~alice/.config/foo")
with subtest("Alternate file locations get overwritten when changed"): with subtest("Alternate file locations get overwritten when changed"):
node1.succeed("${specialisations}/altFilesGetLinked/bin/switch-to-configuration test") node1.succeed("${specialisations}/altFilesGetLinked/bin/switch-to-configuration test")
node1.succeed("${specialisations}/altFilesGetOverwritten/bin/switch-to-configuration test") node1.succeed("${specialisations}/altFilesGetOverwritten/bin/switch-to-configuration test")
node1.succeed("test -L ${userHome}/customCacheDirectory/foo") node1.succeed("test -L ${userHome}/customCacheDirectory/foo")
node1.succeed("grep \"Hello new world!\" ~alice/customCacheDirectory/foo")
node1.succeed("test -L ${userHome}/customConfigDirectory/bar.json") node1.succeed("test -L ${userHome}/customConfigDirectory/bar.json")
node1.succeed("grep \"Hello new second world!\" ~alice/customConfigDirectory/bar.json")
node1.succeed("test -L ${userHome}/customDataDirectory/baz.toml") node1.succeed("test -L ${userHome}/customDataDirectory/baz.toml")
node1.succeed("grep \"Hello new third world!\" ~alice/customDataDirectory/baz.toml")
node1.succeed("test -L ${userHome}/customStateDirectory/foo") node1.succeed("test -L ${userHome}/customStateDirectory/foo")
node1.succeed("grep \"Hello new fourth world!\" ~alice/customStateDirectory/foo")
# Same name as config test file to verify proper merging
node1.succeed("test -L ${userHome}/.config/foo") node1.succeed("test -L ${userHome}/.config/foo")
node1.succeed("grep \"Hello new world!\" ${userHome}/.config/foo") node1.succeed("grep \"Hello new world!\" ~alice/.config/foo")
''; '';
} }

View file

@ -23,9 +23,8 @@ in
alice = { alice = {
enable = true; enable = true;
files = { files = {
"bar.json" = { "foo" = {
generator = (pkgs.formats.toml {}).generate "baz.toml"; text = "Hello world!";
value = {baz = true;};
}; };
}; };
xdg = { xdg = {
@ -42,7 +41,7 @@ in
files = { files = {
"bar.json" = { "bar.json" = {
generator = lib.generators.toJSON {}; generator = lib.generators.toJSON {};
value = {bar = true;}; value = {bar = "Hello second world!";};
}; };
}; };
}; };
@ -51,7 +50,7 @@ in
files = { files = {
"baz.toml" = { "baz.toml" = {
generator = (pkgs.formats.toml {}).generate "baz.toml"; generator = (pkgs.formats.toml {}).generate "baz.toml";
value = {baz = true;}; value = {baz = "Hello third world!";};
}; };
}; };
}; };
@ -59,7 +58,7 @@ in
directory = userHome + "/customStateDirectory"; directory = userHome + "/customStateDirectory";
files = { files = {
"foo" = { "foo" = {
source = pkgs.writeText "file-bar" "Hello World!"; source = pkgs.writeText "file-bar" "Hello fourth world!";
}; };
}; };
}; };
@ -84,18 +83,21 @@ in
machine.succeed("loginctl enable-linger alice") machine.succeed("loginctl enable-linger alice")
machine.wait_until_succeeds("systemctl --user --machine=alice@ is-active systemd-tmpfiles-setup.service") machine.wait_until_succeeds("systemctl --user --machine=alice@ is-active systemd-tmpfiles-setup.service")
# Test XDG files created by Hjem # Test XDG files created by Hjem
with subtest("XDG files created by Hjem"):
machine.succeed("[ -L ~alice/customCacheDirectory/foo ]") machine.succeed("[ -L ~alice/customCacheDirectory/foo ]")
machine.succeed("grep \"Hello world!\" ~alice/customCacheDirectory/foo")
machine.succeed("[ -L ~alice/customConfigDirectory/bar.json ]") machine.succeed("[ -L ~alice/customConfigDirectory/bar.json ]")
machine.succeed("grep \"Hello second world!\" ~alice/customConfigDirectory/bar.json")
machine.succeed("[ -L ~alice/customDataDirectory/baz.toml ]") machine.succeed("[ -L ~alice/customDataDirectory/baz.toml ]")
machine.succeed("grep \"Hello third world!\" ~alice/customDataDirectory/baz.toml")
# Same name as config test file to verify proper merging # Same name as config test file to verify proper merging
machine.succeed("[ -L ~alice/customStateDirectory/foo ]") machine.succeed("[ -L ~alice/customStateDirectory/foo ]")
machine.succeed("grep \"Hello fourth world!\" ~alice/customStateDirectory/foo")
with subtest("Basic test file for Hjem"):
# Basic test file created by Hjem machine.succeed("[ -L ~alice/foo ]") # Same name as cache test file to verify proper merging
# Same name as cache test file to verify proper merging machine.succeed("grep \"Hello world!\" ~alice/foo")
machine.succeed("[ -L ~alice/bar.json ]")
# Test regular files, created by systemd-tmpfiles # Test regular files, created by systemd-tmpfiles
machine.succeed("[ -d ~alice/user_tmpfiles_created ]") machine.succeed("[ -d ~alice/user_tmpfiles_created ]")
machine.succeed("[ -d ~alice/only_alice ]") machine.succeed("[ -d ~alice/only_alice ]")