nixos/tests/whoami: init

This commit is contained in:
Defelo 2025-04-09 16:51:16 +02:00
parent 3ae07e6d12
commit 0e02f935b8
No known key found for this signature in database
GPG key ID: 2A05272471204DD3
3 changed files with 38 additions and 1 deletions

View file

@ -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 { };

32
nixos/tests/whoami.nix Normal file
View file

@ -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)
'';
}

View file

@ -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";