Merge pull request 'Checks: add nixosIntegration test example to hello-service' (#3373) from hsjobeki/clan-core:checks-hello into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3373
This commit is contained in:
@@ -5,4 +5,19 @@
|
|||||||
manifest.name = "clan-core/hello-word";
|
manifest.name = "clan-core/hello-word";
|
||||||
|
|
||||||
roles.peer = { };
|
roles.peer = { };
|
||||||
|
|
||||||
|
perMachine =
|
||||||
|
{ machine, ... }:
|
||||||
|
{
|
||||||
|
nixosModule = {
|
||||||
|
clan.core.vars.generators.hello = {
|
||||||
|
files.hello = {
|
||||||
|
secret = false;
|
||||||
|
};
|
||||||
|
script = ''
|
||||||
|
echo "Hello world from ${machine.name}" > $out/hello
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ in
|
|||||||
hello-world = module;
|
hello-world = module;
|
||||||
};
|
};
|
||||||
perSystem =
|
perSystem =
|
||||||
{ ... }:
|
{ pkgs, ... }:
|
||||||
let
|
let
|
||||||
# Module that contains the tests
|
# Module that contains the tests
|
||||||
# This module adds:
|
# This module adds:
|
||||||
@@ -33,5 +33,22 @@ in
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [ unit-test-module ];
|
imports = [ unit-test-module ];
|
||||||
|
|
||||||
|
/**
|
||||||
|
1. Prepare the test vars
|
||||||
|
nix run .#generate-test-vars -- clanServices/hello-world/tests/vm hello-service
|
||||||
|
|
||||||
|
2. To run the test
|
||||||
|
nix build .#checks.x86_64-linux.hello-service
|
||||||
|
*/
|
||||||
|
checks =
|
||||||
|
# Currently we don't support nixos-integration tests on darwin
|
||||||
|
lib.optionalAttrs (pkgs.stdenv.isLinux) {
|
||||||
|
hello-service = import ./tests/vm/default.nix {
|
||||||
|
inherit module;
|
||||||
|
inherit self inputs pkgs;
|
||||||
|
clanLib = self.clanLib;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
42
clanServices/hello-world/tests/vm/default.nix
Normal file
42
clanServices/hello-world/tests/vm/default.nix
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
self,
|
||||||
|
clanLib,
|
||||||
|
module,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
clanLib.test.makeTestClan {
|
||||||
|
inherit pkgs self;
|
||||||
|
nixosTest = (
|
||||||
|
{ ... }:
|
||||||
|
{
|
||||||
|
name = "service-hello-test";
|
||||||
|
|
||||||
|
clan = {
|
||||||
|
directory = ./.;
|
||||||
|
inventory = {
|
||||||
|
machines.peer1 = { };
|
||||||
|
|
||||||
|
instances."test" = {
|
||||||
|
module.name = "hello-service";
|
||||||
|
roles.peer.machines.peer1 = { };
|
||||||
|
};
|
||||||
|
|
||||||
|
modules = {
|
||||||
|
hello-service = module;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
testScript =
|
||||||
|
{ nodes, ... }:
|
||||||
|
''
|
||||||
|
start_all()
|
||||||
|
|
||||||
|
# peer1 should have the 'hello' file
|
||||||
|
value = peer1.succeed("cat ${nodes.peer1.clan.core.vars.generators.hello.files.hello.path}")
|
||||||
|
assert value.strip() == "Hello world from peer1", value
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"publickey": "age1qm0p4vf9jvcnn43s6l4prk8zn6cx0ep9gzvevxecv729xz540v8qa742eg",
|
||||||
|
"type": "age"
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Hello world from peer1
|
||||||
@@ -4,13 +4,17 @@
|
|||||||
# configures a static age-key to skip the age-key generation
|
# configures a static age-key to skip the age-key generation
|
||||||
sops.age.keyFile = "/run/age-key.txt";
|
sops.age.keyFile = "/run/age-key.txt";
|
||||||
system.activationScripts =
|
system.activationScripts =
|
||||||
|
let
|
||||||
|
# https://github.com/Mic92/sops-nix/blob/61154300d945f0b147b30d24ddcafa159148026a/modules/sops/default.nix#L27
|
||||||
|
hasRegularSecrets = lib.filterAttrs (_: v: v.neededForUsers) config.sops.secrets != { };
|
||||||
|
in
|
||||||
{
|
{
|
||||||
setupSecrets.deps = [ "age-key" ];
|
|
||||||
age-key.text = ''
|
age-key.text = ''
|
||||||
echo AGE-SECRET-KEY-1PL0M9CWRCG3PZ9DXRTTLMCVD57U6JDFE8K7DNVQ35F4JENZ6G3MQ0RQLRV > /run/age-key.txt
|
echo AGE-SECRET-KEY-1PL0M9CWRCG3PZ9DXRTTLMCVD57U6JDFE8K7DNVQ35F4JENZ6G3MQ0RQLRV > /run/age-key.txt
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
// lib.optionalAttrs (lib.filterAttrs (_: v: v.neededForUsers) config.sops.secrets != { }) {
|
// lib.optionalAttrs (hasRegularSecrets) {
|
||||||
|
setupSecrets.deps = [ "age-key" ];
|
||||||
setupSecretsForUsers.deps = [ "age-key" ];
|
setupSecretsForUsers.deps = [ "age-key" ];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user