Compare commits

..

14 commits

3 changed files with 61 additions and 1 deletions

View file

@ -3,6 +3,7 @@
{
imports = [
./options.nix
./simulacrum/test-data.nix
];
services.incandescence = {
@ -15,6 +16,10 @@
./provider-options.nix
];
};
simulacrum.deps = [ "consul" ];
simulacrum = {
enable = true;
deps = [ "consul" "locksmith" ];
settings = ./simulacrum/test.nix;
};
};
}

View file

@ -0,0 +1,8 @@
{ config, lib, ... }:
{
incandescence = lib.mkIf config.simulacrum {
providers = config.lib.forService "incandescence" {
test.objects.example = [ "example1" "example2" ];
};
};
}

View file

@ -0,0 +1,47 @@
{ cluster, lib, ... }:
let
providers = lib.take 2 cluster.config.services.incandescence.nodes.provider;
in
{
nodes = lib.genAttrs providers (lib.const {
services.incandescence.providers.test = {
wantedBy = [ "multi-user.target" ];
partOf = [ ];
formulae.example = {
create = x: "consul kv put testData/${x} ${x}";
destroy = "consul kv delete testData/$OBJECT";
};
};
});
testScript = ''
import json
nodeNames = json.loads('${builtins.toJSON providers}')
nodes = [ n for n in machines if n.name in nodeNames ]
start_all()
consulConfig = json.loads(nodes[0].succeed("cat /etc/consul.json"))
addr = consulConfig["addresses"]["http"]
port = consulConfig["ports"]["http"]
setEnv = f"CONSUL_HTTP_ADDR={addr}:{port}"
with subtest("should create objects"):
for node in nodes:
node.wait_for_unit("incandescence-test.target")
nodes[0].succeed(f"[[ $({setEnv} consul kv get testData/example1) == example1 ]]")
nodes[0].succeed(f"[[ $({setEnv} consul kv get testData/example2) == example2 ]]")
with subtest("should destroy objects"):
nodes[0].succeed(f"{setEnv} consul kv put testData/example3 example3")
nodes[0].succeed(f"{setEnv} consul kv put services/incandescence/providers/test/formulae/example/example3/alive true")
nodes[1].succeed(f"{setEnv} consul kv get testData/example3")
for node in nodes:
node.systemctl("isolate default")
for node in nodes:
node.wait_for_unit("incandescence-test.target")
nodes[0].fail(f"{setEnv} consul kv get testData/example3")
'';
}