Fediversity/deployment/utils-test.nix

89 lines
1.4 KiB
Nix

let
inherit (import ../default.nix { }) pkgs;
inherit (pkgs.callPackage ./utils.nix { })
mapKeys
evalOption
toBash
withPackages
filterNull
withEnv
;
inherit (pkgs) lib;
inherit (lib) mkOption types;
inherit (types) submodule;
in
{
_class = "nix-unit";
test-mapKeys = {
expr = mapKeys (k: "${k}${k}") { a = 1; };
expected = {
aa = 1;
};
};
test-evalOption = {
expr = evalOption (mkOption {
type = submodule {
options = {
a = mkOption { default = 3; };
};
};
}) { };
expected = {
a = 3;
};
};
test-toBash-int = {
expr = toBash 1;
expected = "1";
};
test-toBash-null = {
expr = toBash null;
expected = "";
};
test-toBash-attrs = {
expr = toBash { a = 1; };
expected = ''{\"a\":1}'';
};
test-toBash-str = {
expr = toBash "'b\"";
expected = "'b\\\"";
};
test-withPackages = {
expr = withPackages [ pkgs.hello ];
expected = {
makeWrapperArgs = [
"--prefix"
"PATH"
":"
"${lib.makeBinPath [ pkgs.hello ]}"
];
};
};
test-filterNull = {
expr = filterNull {
a = 4;
b = null;
};
expected = {
a = 4;
};
};
test-withEnv = {
expr = withEnv {
a = 1;
b = null;
c = "'d\"";
e.f = [ "g" ];
};
expected = ''a="1" b="" c="'d\"" e="{\"f\":[\"g\"]}"'';
};
}