add test for function.nix (#578)

Reviewed-on: fediversity/fediversity#578
This commit is contained in:
Kiara Grouwstra 2025-11-08 16:08:07 +01:00
parent 98b39012f0
commit c0024739b2
2 changed files with 114 additions and 0 deletions

View file

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

View file

@ -0,0 +1,108 @@
let
inherit (import ../default.nix { }) pkgs;
inherit (pkgs) lib;
inherit (builtins) tryEval;
inherit (lib) mkOption types;
inherit (types)
int
str
submodule
;
functionType = submodule ./function.nix;
in
{
_class = "nix-unit";
test-function-ok = {
expr =
tryEval
(lib.evalModules {
modules = [
(
{ config, ... }:
{
options = {
fn = mkOption {
type = functionType;
};
call = mkOption {
default = config.fn.apply 1;
};
};
config.fn = {
implementation = x: x;
input-type = int;
output-type = int;
};
}
)
];
}).config.call;
expected = {
success = true;
value = 1;
};
};
test-bad-input = {
expr =
tryEval
(lib.evalModules {
modules = [
(
{ config, ... }:
{
options = {
fn = mkOption {
type = functionType;
};
call = mkOption {
default = config.fn.apply 1;
};
};
config.fn = {
implementation = x: x;
input-type = str;
output-type = int;
};
}
)
];
}).config.call;
expected = {
success = false;
value = false;
};
};
test-bad-output = {
expr =
tryEval
(lib.evalModules {
modules = [
(
{ config, ... }:
{
options = {
fn = mkOption {
type = functionType;
};
call = mkOption {
default = config.fn.apply 1;
};
};
config.fn = {
implementation = x: x;
input-type = int;
output-type = str;
};
}
)
];
}).config.call;
expected = {
success = false;
value = false;
};
};
}