test utils (#581)

Reviewed-on: fediversity/fediversity#581
This commit is contained in:
Kiara Grouwstra 2025-11-10 14:07:49 +01:00
parent 18bc596e76
commit ef5202d8a8
2 changed files with 95 additions and 0 deletions

View file

@ -14,6 +14,12 @@ concurrency:
group: ${{ forgejo.workflow }}-${{ forgejo.event.pull_request.number || forgejo.ref }} group: ${{ forgejo.workflow }}-${{ forgejo.event.pull_request.number || forgejo.ref }}
jobs: jobs:
check-utils:
runs-on: native
steps:
- uses: actions/checkout@v4
- run: nix-shell --run 'nix-unit ./deployment/utils-test.nix'
check-function: check-function:
runs-on: native runs-on: native
steps: steps:

89
deployment/utils-test.nix Normal file
View file

@ -0,0 +1,89 @@
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\"]}"'';
};
}