about summary refs log tree commit diff
path: root/nixos/tests/goss.nix
blob: 2e77b2734464f4888772ddf80d36b876b3733f3e (plain) (blame)
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
39
40
41
42
43
44
45
46
47
48
49
import ./make-test-python.nix ({ pkgs, lib, ... }: {
  name = "goss";
  meta.maintainers = [ lib.maintainers.anthonyroussel ];

  nodes.machine = {
    environment.systemPackages = [ pkgs.jq ];

    services.goss = {
      enable = true;

      environment = {
        GOSS_FMT = "json";
      };

      settings = {
        addr."tcp://localhost:8080" = {
          reachable = true;
          local-address = "127.0.0.1";
        };
        command."check-goss-version" = {
          exec = "${lib.getExe pkgs.goss} --version";
          exit-status = 0;
        };
        dns.localhost.resolvable = true;
        file."/nix" = {
          filetype = "directory";
          exists = true;
        };
        group.root.exists = true;
        kernel-param."kernel.ostype".value = "Linux";
        user.root.exists = true;
      };
    };
  };

  testScript = ''
    import json

    machine.wait_for_unit("goss.service")
    machine.wait_for_open_port(8080)

    with subtest("returns health status"):
      result = json.loads(machine.succeed("curl -sS http://localhost:8080/healthz"))

      assert len(result["results"]) == 8, f".results should be an array of 10 items, was {result['results']!r}"
      assert result["summary"]["failed-count"] == 0, f".summary.failed-count should be zero, was {result['summary']['failed-count']}"
      assert result["summary"]["test-count"] == 8, f".summary.test-count should be 10, was {result['summary']['test-count']}"
    '';
})