diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index d96fce4d500f..13d26b083ac8 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -1445,6 +1445,7 @@ in webhook = runTest ./webhook.nix; weblate = handleTest ./web-apps/weblate.nix { }; whisparr = handleTest ./whisparr.nix { }; + whoami = runTest ./whoami.nix; whoogle-search = handleTest ./whoogle-search.nix { }; wiki-js = runTest ./wiki-js.nix; wine = handleTest ./wine.nix { }; diff --git a/nixos/tests/whoami.nix b/nixos/tests/whoami.nix new file mode 100644 index 000000000000..165d8ddb8072 --- /dev/null +++ b/nixos/tests/whoami.nix @@ -0,0 +1,32 @@ +{ lib, ... }: + +{ + name = "echoip"; + meta.maintainers = with lib.maintainers; [ defelo ]; + + nodes.machine = { + services.whoami.enable = true; + }; + + interactive.nodes.machine = { + networking.firewall.allowedTCPPorts = [ 8000 ]; + virtualisation.forwardPorts = [ + { + from = "host"; + host.port = 8000; + guest.port = 8000; + } + ]; + }; + + testScript = '' + import re + + machine.wait_for_unit("whoami.service") + machine.wait_for_open_port(8000) + + response = machine.succeed("curl -H 'X-Test-Header: Hello World!' http://127.0.0.1:8000/test") + assert re.search(r"^GET /test", response, re.M) + assert re.search(r"^X-Test-Header: Hello World!", response, re.M) + ''; +} diff --git a/pkgs/by-name/wh/whoami/package.nix b/pkgs/by-name/wh/whoami/package.nix index 28da64a7298f..d3a7006aceaa 100644 --- a/pkgs/by-name/wh/whoami/package.nix +++ b/pkgs/by-name/wh/whoami/package.nix @@ -2,6 +2,7 @@ lib, buildGoModule, fetchFromGitHub, + nixosTests, nix-update-script, }: @@ -31,7 +32,10 @@ buildGoModule (finalAttrs: { runHook postInstallCheck ''; - passthru.updateScript = nix-update-script { }; + passthru = { + tests = { inherit (nixosTests) whoami; }; + updateScript = nix-update-script { }; + }; meta = { description = "Tiny Go server that prints os information and HTTP request to output";