Checks: add nixosIntegration test example to hello-service

This commit is contained in:
Johannes Kirschbauer
2025-04-21 18:39:09 +02:00
committed by Mic92
parent bcc4aa9902
commit 999c47dbed
6 changed files with 82 additions and 3 deletions

View File

@@ -5,4 +5,19 @@
manifest.name = "clan-core/hello-word";
roles.peer = { };
perMachine =
{ machine, ... }:
{
nixosModule = {
clan.core.vars.generators.hello = {
files.hello = {
secret = false;
};
script = ''
echo "Hello world from ${machine.name}" > $out/hello
'';
};
};
};
}

View File

@@ -14,7 +14,7 @@ in
hello-world = module;
};
perSystem =
{ ... }:
{ pkgs, ... }:
let
# Module that contains the tests
# This module adds:
@@ -33,5 +33,18 @@ in
in
{
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.hello-service = import ./tests/vm/default.nix {
inherit module;
inherit self inputs pkgs;
clanLib = self.clanLib;
};
};
}

View 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
'';
}
);
}

View File

@@ -0,0 +1,4 @@
{
"publickey": "age1qm0p4vf9jvcnn43s6l4prk8zn6cx0ep9gzvevxecv729xz540v8qa742eg",
"type": "age"
}

View File

@@ -0,0 +1 @@
Hello world from peer1