refactor(clanServices): add example of eval test
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
{ self, lib, ... }:
|
|
||||||
{
|
{
|
||||||
clan.inventory.modules = {
|
imports = [
|
||||||
zerotier-redux = lib.modules.importApply ./zerotier-redux/default.nix {
|
./zerotier-redux/flake-module.nix
|
||||||
inherit (self) packages;
|
];
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
41
clanServices/zerotier-redux/flake-module.nix
Normal file
41
clanServices/zerotier-redux/flake-module.nix
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
{
|
||||||
|
self,
|
||||||
|
lib,
|
||||||
|
inputs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
inputOverrides = builtins.concatStringsSep " " (
|
||||||
|
builtins.map (input: " --override-input ${input} ${inputs.${input}}") (builtins.attrNames inputs)
|
||||||
|
);
|
||||||
|
|
||||||
|
module = lib.modules.importApply ./default.nix {
|
||||||
|
inherit (self) packages;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
clan.inventory.modules = {
|
||||||
|
zerotier-redux = module;
|
||||||
|
};
|
||||||
|
perSystem =
|
||||||
|
{ system, pkgs, ... }:
|
||||||
|
{
|
||||||
|
legacyPackages.eval-tests-zerotier-redux = import ./tests/eval-tests.nix {
|
||||||
|
inherit lib module;
|
||||||
|
inherit (self) clanLib;
|
||||||
|
};
|
||||||
|
checks = {
|
||||||
|
"eval-tests-zerotier-redux" = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
|
||||||
|
export HOME="$(realpath .)"
|
||||||
|
|
||||||
|
nix-unit --eval-store "$HOME" \
|
||||||
|
--extra-experimental-features flakes \
|
||||||
|
--show-trace \
|
||||||
|
${inputOverrides} \
|
||||||
|
--flake ${self}#legacyPackages.${system}.eval-tests-zerotier-redux
|
||||||
|
|
||||||
|
touch $out
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
53
clanServices/zerotier-redux/tests/eval-tests.nix
Normal file
53
clanServices/zerotier-redux/tests/eval-tests.nix
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
{
|
||||||
|
module,
|
||||||
|
clanLib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
testFlake = clanLib.buildClan {
|
||||||
|
# Point to the folder of the module
|
||||||
|
# TODO: make this optional in buildClan
|
||||||
|
directory = ./..;
|
||||||
|
|
||||||
|
# Create some test machines
|
||||||
|
machines.jon = {
|
||||||
|
nixpkgs.hostPlatform = "x86_64-linux";
|
||||||
|
};
|
||||||
|
machines.sara = {
|
||||||
|
nixpkgs.hostPlatform = "x86_64-linux";
|
||||||
|
};
|
||||||
|
|
||||||
|
# Register the module for the test
|
||||||
|
inventory.modules.zerotier-redux = module;
|
||||||
|
|
||||||
|
# Use the module in the test
|
||||||
|
inventory.instances = {
|
||||||
|
"zero" = {
|
||||||
|
module.name = "zerotier-redux";
|
||||||
|
|
||||||
|
roles.peer.machines.jon = { };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
# NOTE:
|
||||||
|
# If you wonder why 'self-zerotier-redux':
|
||||||
|
# A local module has prefix 'self', otherwise it is the name of the 'input'
|
||||||
|
# The rest is the name of the service as in the instance 'module.name';
|
||||||
|
#
|
||||||
|
# -> ${module.input}-${module.name}
|
||||||
|
# In this case it is 'self-zerotier-redux'
|
||||||
|
# This is usually only used internally, but we can use it to test the evaluation of service module in isolation
|
||||||
|
# evaluatedService =
|
||||||
|
# testFlake.clanInternals.inventoryClass.distributedServices.importedModulesEvaluated.self-zerotier-redux.config;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
test_simple = {
|
||||||
|
inherit testFlake;
|
||||||
|
|
||||||
|
expr = {
|
||||||
|
};
|
||||||
|
expected = {
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user