From c0024739b24d154cfe816f18d3f7defb8dcc8d3d Mon Sep 17 00:00:00 2001 From: Kiara Grouwstra Date: Sat, 8 Nov 2025 16:08:07 +0100 Subject: [PATCH] add test for function.nix (#578) Reviewed-on: https://git.fediversity.eu/fediversity/fediversity/pulls/578 --- .forgejo/workflows/ci.yaml | 6 ++ deployment/function-test.nix | 108 +++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 deployment/function-test.nix 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; + }; + }; +}