summaryrefslogtreecommitdiffstats
path: root/nixos/tests/go-httpbin.nix
blob: 318fd8886c58e0278b7ee91fcc445ca405108550 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
{ lib, ... }:

{
  name = "go-httpbin";
  meta.maintainers = with lib.maintainers; [ defelo ];

  nodes.machine = {
    services.go-httpbin = {
      enable = true;
      settings.PORT = 8000;
    };
  };

  interactive.nodes.machine = {
    services.go-httpbin.settings.HOST = "0.0.0.0";
    networking.firewall.allowedTCPPorts = [ 8000 ];
    virtualisation.forwardPorts = [
      {
        from = "host";
        host.port = 8000;
        guest.port = 8000;
      }
    ];
  };

  testScript = ''
    import json

    machine.wait_for_unit("go-httpbin.service")
    machine.wait_for_open_port(8000)

    resp = json.loads(machine.succeed("curl localhost:8000/get?foo=bar"))
    assert resp["args"]["foo"] == ["bar"]
    assert resp["method"] == "GET"
    assert resp["origin"] == "127.0.0.1"
    assert resp["url"] == "http://localhost:8000/get?foo=bar"
  '';
}