2021-04-18 01:35:05 +00:00
|
|
|
{ pkgs, lib, ... }:
|
|
|
|
with lib;
|
2021-03-14 07:10:51 +00:00
|
|
|
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; };
|
|
|
|
};
|
|
|
|
|
2021-04-10 17:59:10 +00:00
|
|
|
testPathsIn = {
|
|
|
|
expr = pathsIn (toString ./testPathsIn);
|
2021-03-14 07:10:51 +00:00
|
|
|
|
2021-04-10 17:59:10 +00:00
|
|
|
expected = map toString [
|
|
|
|
./testPathsIn/bar
|
|
|
|
./testPathsIn/baz
|
|
|
|
./testPathsIn/foo
|
|
|
|
];
|
|
|
|
};
|
2021-03-14 07:10:51 +00:00
|
|
|
|
|
|
|
testPathsToImportedAttrs = {
|
|
|
|
expr =
|
|
|
|
pathsToImportedAttrs [
|
2021-04-10 17:59:10 +00:00
|
|
|
(toString ./testPathsToImportedAttrs/dir)
|
|
|
|
./testPathsToImportedAttrs/foo.nix
|
|
|
|
./testPathsToImportedAttrs/bar.nix
|
|
|
|
./testPathsToImportedAttrs/t.nix
|
|
|
|
./testPathsToImportedAttrs/f.nix
|
2021-03-14 07:10:51 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
expected = {
|
2021-03-28 06:18:27 +00:00
|
|
|
dir = { a = 5; };
|
2021-03-14 07:10:51 +00:00
|
|
|
foo = { bar = 1; };
|
|
|
|
bar = { foo = 2; };
|
|
|
|
t = true;
|
|
|
|
f = false;
|
|
|
|
};
|
|
|
|
};
|
2021-03-15 03:40:49 +00:00
|
|
|
|
|
|
|
testRgxToString = lib.testAllTrue [
|
|
|
|
(rgxToString ".+x" "vxk" == "vx")
|
|
|
|
(rgxToString "^fo" "foo" == "fo")
|
|
|
|
(rgxToString "a?" "a" == "a")
|
|
|
|
(rgxToString "hat" "foohatbar" == "hat")
|
|
|
|
];
|
2021-03-28 22:05:47 +00:00
|
|
|
|
2021-03-30 19:47:54 +00:00
|
|
|
testSafeReadDir = {
|
2021-04-10 17:59:10 +00:00
|
|
|
expr = safeReadDir ./profiles // safeReadDir ./nonexistentdir;
|
2021-03-30 19:47:54 +00:00
|
|
|
expected = {
|
|
|
|
foo = "directory";
|
|
|
|
t = "directory";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-03-28 22:05:47 +00:00
|
|
|
testSuites =
|
|
|
|
let
|
|
|
|
profiles = os.mkProfileAttrs (toString ./profiles);
|
|
|
|
users = "";
|
|
|
|
userProfiles = "";
|
|
|
|
suites = { profiles, ... }: {
|
|
|
|
system.bar = [ profiles.foo ];
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
expr = os.mkSuites { inherit profiles users userProfiles suites; };
|
|
|
|
expected = {
|
|
|
|
system = {
|
|
|
|
bar = [ profiles.foo.default ];
|
|
|
|
allProfiles = [ profiles.foo.default profiles.t.default ];
|
2021-04-10 01:22:08 +00:00
|
|
|
allUsers = [ ];
|
2021-03-28 22:05:47 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2021-03-14 07:10:51 +00:00
|
|
|
}
|