diff --git a/.forgejo/workflows/ci.yaml b/.forgejo/workflows/ci.yaml index 4a925e84..9046ae7d 100644 --- a/.forgejo/workflows/ci.yaml +++ b/.forgejo/workflows/ci.yaml @@ -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: diff --git a/deployment/function-test.nix b/deployment/function-test.nix new file mode 100644 index 00000000..73f306ce --- /dev/null +++ b/deployment/function-test.nix @@ -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; + }; + }; +}