From 37914c29bee4957c291df4fc2e703a0786078fc7 Mon Sep 17 00:00:00 2001 From: Defelo Date: Tue, 1 Apr 2025 02:33:56 +0200 Subject: [PATCH] nixos/tests/olivetin: init --- nixos/tests/all-tests.nix | 1 + nixos/tests/olivetin.nix | 57 ++++++++++++++++++++++++++++ pkgs/by-name/ol/olivetin/package.nix | 2 + 3 files changed, 60 insertions(+) create mode 100644 nixos/tests/olivetin.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index e3e2f5763d17..65f3b6316a19 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -966,6 +966,7 @@ in oddjobd = handleTestOn [ "x86_64-linux" "aarch64-linux" ] ./oddjobd.nix { }; obs-studio = runTest ./obs-studio.nix; oh-my-zsh = handleTest ./oh-my-zsh.nix { }; + olivetin = runTest ./olivetin.nix; ollama = runTest ./ollama.nix; ollama-cuda = runTestOn [ "x86_64-linux" "aarch64-linux" ] ./ollama-cuda.nix; ollama-rocm = runTestOn [ "x86_64-linux" "aarch64-linux" ] ./ollama-rocm.nix; diff --git a/nixos/tests/olivetin.nix b/nixos/tests/olivetin.nix new file mode 100644 index 000000000000..f9d9e98610ef --- /dev/null +++ b/nixos/tests/olivetin.nix @@ -0,0 +1,57 @@ +{ lib, ... }: + +{ + name = "olivetin"; + meta.maintainers = with lib.maintainers; [ defelo ]; + + nodes.machine = { + services.olivetin = { + enable = true; + settings = { + actions = [ + { + id = "hello_world"; + title = "Say Hello"; + shell = "echo -n 'Hello World!' | tee /tmp/result"; + } + ]; + }; + extraConfigFiles = [ + (builtins.toFile "secrets.yaml" '' + actions: + - id: secret + title: Secret Action + shell: echo -n secret > /tmp/result2 + '') + ]; + }; + }; + + interactive.nodes.machine = { + services.olivetin.settings.ListenAddressSingleHTTPFrontend = "0.0.0.0:8000"; + networking.firewall.allowedTCPPorts = [ 8000 ]; + virtualisation.forwardPorts = [ + { + from = "host"; + host.port = 8000; + guest.port = 8000; + } + ]; + }; + + testScript = '' + import json + + machine.wait_for_unit("olivetin.service") + machine.wait_for_open_port(8000) + + response = json.loads(machine.succeed("curl http://localhost:8000/api/StartActionByGetAndWait/hello_world")) + assert response["logEntry"]["exitCode"] == 0 + assert response["logEntry"]["output"] == "Hello World!" + assert machine.succeed("cat /tmp/result") == "Hello World!" + + response = json.loads(machine.succeed("curl http://localhost:8000/api/StartActionByGetAndWait/secret")) + assert response["logEntry"]["exitCode"] == 0 + assert machine.succeed("cat /tmp/result2") == "secret" + ''; +} diff --git a/pkgs/by-name/ol/olivetin/package.nix b/pkgs/by-name/ol/olivetin/package.nix index 00920ba1790a..24cb51325a2a 100644 --- a/pkgs/by-name/ol/olivetin/package.nix +++ b/pkgs/by-name/ol/olivetin/package.nix @@ -11,6 +11,7 @@ buildNpmPackage, installShellFiles, versionCheckHook, + nixosTests, }: buildGoModule ( @@ -122,6 +123,7 @@ buildGoModule ( passthru = { inherit gen webui; + tests = { inherit (nixosTests) olivetin; }; updateScript = ./update.sh; };