forked from fediversity/fediversity
add test for function.nix (#578)
Reviewed-on: fediversity/fediversity#578
This commit is contained in:
parent
98b39012f0
commit
c0024739b2
2 changed files with 114 additions and 0 deletions
|
|
@ -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:
|
||||
|
|
|
|||
108
deployment/function-test.nix
Normal file
108
deployment/function-test.nix
Normal 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;
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue