diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 0bc01b90551f..71a18ed9e343 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -702,6 +702,7 @@ in gobgpd = runTest ./gobgpd.nix; gocd-agent = runTest ./gocd-agent.nix; gocd-server = runTest ./gocd-server.nix; + gocron = runTest ./gocron.nix; gocryptfs = runTest ./gocryptfs.nix; gokapi = runTest ./gokapi.nix; gollum = runTest ./gollum.nix; diff --git a/nixos/tests/gocron.nix b/nixos/tests/gocron.nix new file mode 100644 index 000000000000..2625dc474b53 --- /dev/null +++ b/nixos/tests/gocron.nix @@ -0,0 +1,58 @@ +{ pkgs, ... }: + +{ + name = "gocron"; + meta.maintainers = with pkgs.lib.maintainers; [ juliusfreudenberger ]; + + nodes.machine = + { pkgs, ... }: + { + environment.systemPackages = [ pkgs.jq ]; + services.gocron = { + enable = true; + settings = { + jobs = [ + { + name = "Test job"; + disabled_cron = true; + commands = [ + "echo 'Job runs successfully'" + ]; + } + ]; + }; + }; + }; + + testScript = '' + def gocron_is_up(_) -> bool: + status, _ = machine.execute("curl --fail http://localhost:8156") + return status == 0 + + def job_is_available() -> bool: + status, output = machine.execute("curl http://localhost:8156/api/jobs | jq '. | length'") + return status == 0 and int(output) == 1 + + def start_job(): + machine.succeed("curl -X POST http://localhost:8156/api/jobs/Test%20job") + + def job_ran_successfully() -> bool: + output = machine.succeed("curl http://localhost:8156/api/runs/Test%20job | jq '.[0].status_id, .[0].logs.[2].message'") + split_output = output.split('\n') + ran_successfully = int(split_output[0]) == 3 + log_message_as_expected = "Job runs not successfully" in split_output[1] + return ran_successfully and log_message_as_expected + + machine.wait_for_unit("gocron.service") + machine.wait_for_open_port(8156) + with machine.nested("Waiting for UI to work"): + retry(gocron_is_up) + + with machine.nested("Test job"): + if not job_is_available(): + exit(1) + start_job() + if not job_ran_successfully(): + exit(1) + ''; +} diff --git a/pkgs/by-name/go/gocron/package.nix b/pkgs/by-name/go/gocron/package.nix index e93a8745a476..bc9ea1e8dd31 100644 --- a/pkgs/by-name/go/gocron/package.nix +++ b/pkgs/by-name/go/gocron/package.nix @@ -12,6 +12,7 @@ bash, versionCheckHook, nix-update-script, + nixosTests, }: buildGoModule (finalAttrs: { @@ -93,6 +94,7 @@ buildGoModule (finalAttrs: { "gocron-web" ]; }; + passthru.tests = nixosTests.gocron; meta = { description = "Task scheduler built with Go and Vue.js.";