diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 7ef0a3a4a368..de6bd2654a4c 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -1531,6 +1531,7 @@ in tor = runTest ./tor.nix; tpm-ek = handleTest ./tpm-ek { }; tpm2 = runTest ./tpm2.nix; + traccar = runTest ./traccar.nix; # tracee requires bpf tracee = handleTestOn [ "x86_64-linux" ] ./tracee.nix { }; traefik = runTestOn [ "aarch64-linux" "x86_64-linux" ] ./traefik.nix; diff --git a/nixos/tests/traccar.nix b/nixos/tests/traccar.nix new file mode 100644 index 000000000000..73b0c637e620 --- /dev/null +++ b/nixos/tests/traccar.nix @@ -0,0 +1,51 @@ +{ + pkgs, + lib, + ... +}: +{ + name = "traccar"; + meta = { + maintainers = with lib.maintainers; [ frederictobiasc ]; + }; + nodes.machine = { + services.traccar = { + enable = true; + settings.mail.smtp.host = "$SMTP_HOST"; + environmentFile = pkgs.writeText "traccar.env" '' + SMTP_HOST=smtp.example.com + ''; + }; + }; + testScript = '' + machine.wait_for_unit("traccar.service") + + # Check that environment variables were substituted + t.assertIn("smtp.example.com", machine.succeed("cat /var/lib/traccar/config.xml"), "environment substitution failed") + + machine.wait_for_open_port(8082) + + # Check that we get the traccar login page + t.assertIn("Traccar", machine.wait_until_succeeds("curl -sf http://localhost:8082/"), "Traccar frontend seems unreachable") + + # Register the first admin user + register_data = """ + { + "email": "admin@example.com", + "name": "admin", + "password": "admin123" + } + """ + + t.assertIn( + "\"administrator\":true", + machine.succeed( + "curl -s -X POST " + "-H 'Content-Type: application/json' " + f"-d '{register_data}' " + "http://localhost:8082/api/users" + ), + "Unexpected registration response" + ) + ''; +}