about summary refs log tree commit diff
path: root/nixos/tests/gocd-agent.nix
blob: 9301a88ec05d83ec737e91d2501fdf5a5f701778 (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
# verifies:
#   1. GoCD agent starts
#   2. GoCD agent responds
#   3. GoCD agent is available on GoCD server using GoCD API
#     3.1. https://api.go.cd/current/#get-all-agents

let
  serverUrl = "localhost:8153/go/api/agents";
  header = "Accept: application/vnd.go.cd.v2+json";
in

import ./make-test-python.nix ({ pkgs, ...} : {
  name = "gocd-agent";
  meta = with pkgs.lib.maintainers; {
    maintainers = [ grahamc swarren83 ];

    # gocd agent needs to register with the autoregister key created on first server startup,
    # but NixOS module doesn't seem to allow to pass during runtime currently
    broken = true;
  };

  nodes = {
    agent =
      { ... }:
      {
        virtualisation.memorySize = 2046;
        services.gocd-agent = {
          enable = true;
        };
        services.gocd-server = {
          enable = true;
        };
      };
  };

  testScript = ''
    start_all()
    agent.wait_for_unit("gocd-server")
    agent.wait_for_open_port(8153)
    agent.wait_for_unit("gocd-agent")
    agent.wait_until_succeeds(
        "curl ${serverUrl} -H '${header}' | ${pkgs.jq}/bin/jq -e ._embedded.agents[0].uuid"
    )
    agent.succeed(
        "curl ${serverUrl} -H '${header}' | ${pkgs.jq}/bin/jq -e ._embedded.agents[0].agent_state | grep Idle"
    )
  '';
})