1
1
mirror of https://github.com/divnix/digga.git synced 2024-12-24 00:21:47 +03:00
digga/tests/lib.nix
Pacman99 237e0bce9b rakeLeaves: create and use standard auto-importer
The function picks up `.nix` files and stops recursing when it hits
a folder with a `default.nix`
This allows it to be used to collect hosts, overlays, and profiles
2022-02-23 15:22:57 -08:00

62 lines
1.4 KiB
Nix

{ pkgs, lib }:
with lib;
lib.runTests {
testConcatAttrs = {
expr = concatAttrs [{ foo = 1; } { bar = 2; } { baz = 3; }];
expected = { foo = 1; bar = 2; baz = 3; };
};
testGenAttrs' = {
expr = genAttrs'
[ "/foo/bar" "/baz/buzz" ]
(path: {
name = baseNameOf path;
value = "${path}/fizz";
});
expected = { bar = "/foo/bar/fizz"; buzz = "/baz/buzz/fizz"; };
};
testMapFilterAttrs = {
expr = mapFilterAttrs
(n: v: n == "foobar" && v == 1)
(n: v: lib.nameValuePair ("${n}bar") (v + 1))
{ foo = 0; bar = 2; };
expected = { foobar = 1; };
};
testRgxToString = lib.testAllTrue [
(rgxToString ".+x" "vxk" == "vx")
(rgxToString "^fo" "foo" == "fo")
(rgxToString "a?" "a" == "a")
(rgxToString "hat" "foohatbar" == "hat")
];
testSafeReadDir = {
expr = safeReadDir ./profiles // safeReadDir ./nonexistentdir;
expected = {
foo = "directory";
t = "directory";
"f.nix" = "regular";
};
};
testSuites = {
expr = mkSuites {
suites = { profiles, ... }: with profiles; {
bar = [ foo f ];
};
profiles = [ (./profiles) ];
};
expected = {
bar = [ (toString ./profiles/foo) (toString ./profiles/f.nix) ];
allProfiles = [
(toString ./profiles/foo)
(toString ./profiles/f.nix)
];
};
};
}