From 476de03bf4beb519367077baf1931c1998a7ddae Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Mon, 30 Mar 2026 17:45:17 -0400 Subject: [PATCH] tests: add NixOS VM test for gitea actions runner --- tests/gitea-runner.nix | 60 ++++++++++++++++++++++++++++++++++++++++++ tests/tests.nix | 3 +++ 2 files changed, 63 insertions(+) create mode 100644 tests/gitea-runner.nix diff --git a/tests/gitea-runner.nix b/tests/gitea-runner.nix new file mode 100644 index 0000000..dbf98d3 --- /dev/null +++ b/tests/gitea-runner.nix @@ -0,0 +1,60 @@ +{ + config, + lib, + pkgs, + ... +}: +pkgs.testers.runNixOSTest { + name = "gitea-runner"; + nodes.machine = + { pkgs, ... }: + { + services.gitea = { + enable = true; + database.type = "sqlite3"; + settings = { + server = { + HTTP_PORT = 3000; + ROOT_URL = "http://localhost:3000"; + DOMAIN = "localhost"; + }; + actions.ENABLED = true; + service.DISABLE_REGISTRATION = true; + }; + }; + + specialisation.runner = { + inheritParentConfig = true; + configuration.services.gitea-actions-runner.instances.test = { + enable = true; + name = "ci"; + url = "http://localhost:3000"; + labels = [ "native:host" ]; + tokenFile = "/var/lib/gitea/runner_token"; + }; + }; + }; + + testScript = '' + start_all() + + machine.wait_for_unit("gitea.service") + machine.wait_for_open_port(3000) + + # Generate runner token + machine.succeed( + "su -l gitea -s /bin/sh -c '${pkgs.gitea}/bin/gitea actions generate-runner-token --work-path /var/lib/gitea' | tail -1 | sed 's/^/TOKEN=/' > /var/lib/gitea/runner_token" + ) + + # Switch to runner specialisation + machine.succeed( + "/run/current-system/specialisation/runner/bin/switch-to-configuration test" + ) + + # Start the runner (specialisation switch doesn't auto-start new services) + machine.succeed("systemctl start gitea-runner-test.service") + machine.wait_for_unit("gitea-runner-test.service") + machine.succeed("sleep 5") + machine.succeed("test -f /var/lib/gitea-runner/test/.runner") + ''; +} diff --git a/tests/tests.nix b/tests/tests.nix index 27684a2..44b1db0 100644 --- a/tests/tests.nix +++ b/tests/tests.nix @@ -27,4 +27,7 @@ in # torrent audit test torrentAuditTest = handleTest ./torrent-audit.nix; + + # gitea runner test + giteaRunnerTest = handleTest ./gitea-runner.nix; }