From d784ee0a8684f5bb96a4a09a593f760419eaee80 Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 23 Jul 2024 02:47:01 +0200 Subject: [PATCH] cluster/services/consul: test in simulacrum --- cluster/services/consul/default.nix | 5 +++++ cluster/services/consul/test.nix | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 cluster/services/consul/test.nix diff --git a/cluster/services/consul/default.nix b/cluster/services/consul/default.nix index d7855b6..ee4e374 100644 --- a/cluster/services/consul/default.nix +++ b/cluster/services/consul/default.nix @@ -22,6 +22,11 @@ in ]; ready = ./ready.nix; }; + simulacrum = { + enable = true; + deps = [ "wireguard" ]; + settings = ./test.nix; + }; }; dns.records."consul-remote.internal".consulService = "consul-remote"; diff --git a/cluster/services/consul/test.nix b/cluster/services/consul/test.nix new file mode 100644 index 0000000..3a279bb --- /dev/null +++ b/cluster/services/consul/test.nix @@ -0,0 +1,19 @@ +{ + testScript = '' + import json + + start_all() + + with subtest("should form cluster"): + for machine in machines: + machine.succeed("systemctl start consul-ready.service") + for machine in machines: + consulConfig = json.loads(machine.succeed("cat /etc/consul.json")) + addr = consulConfig["addresses"]["http"] + port = consulConfig["ports"]["http"] + setEnv = f"CONSUL_HTTP_ADDR={addr}:{port}" + memberList = machine.succeed(f"{setEnv} consul members --status=alive") + for machine2 in machines: + assert machine2.name in memberList + ''; +}