feat(clan/services): init test-suite for eval test
This commit is contained in:
54
lib/distributed-service/flake-module.nix
Normal file
54
lib/distributed-service/flake-module.nix
Normal file
@@ -0,0 +1,54 @@
|
||||
{ self, inputs, ... }:
|
||||
let
|
||||
inputOverrides = builtins.concatStringsSep " " (
|
||||
builtins.map (input: " --override-input ${input} ${inputs.${input}}") (builtins.attrNames inputs)
|
||||
);
|
||||
in
|
||||
{
|
||||
perSystem =
|
||||
{
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
system,
|
||||
self',
|
||||
...
|
||||
}:
|
||||
{
|
||||
devShells.inventory-schema = pkgs.mkShell {
|
||||
inputsFrom = with config.checks; [
|
||||
lib-inventory-eval
|
||||
self'.devShells.default
|
||||
];
|
||||
};
|
||||
|
||||
legacyPackages.schemas = (
|
||||
import ./schemas {
|
||||
inherit
|
||||
pkgs
|
||||
self
|
||||
lib
|
||||
self'
|
||||
;
|
||||
}
|
||||
);
|
||||
|
||||
# Run: nix-unit --extra-experimental-features flakes --flake .#legacyPackages.x86_64-linux.<attrName>
|
||||
legacyPackages.evalTest-distributedServices = import ./tests {
|
||||
inherit lib self;
|
||||
};
|
||||
|
||||
checks = {
|
||||
lib-distributedServices-eval = pkgs.runCommand "tests" { nativeBuildInputs = [ pkgs.nix-unit ]; } ''
|
||||
export HOME="$(realpath .)"
|
||||
export NIX_ABORT_ON_WARN=1
|
||||
nix-unit --eval-store "$HOME" \
|
||||
--extra-experimental-features flakes \
|
||||
${inputOverrides} \
|
||||
--flake ${self}#legacyPackages.${system}.distributedServices
|
||||
|
||||
touch $out
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
61
lib/distributed-service/tests/default.nix
Normal file
61
lib/distributed-service/tests/default.nix
Normal file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib)
|
||||
evalModules
|
||||
mkOption
|
||||
types
|
||||
;
|
||||
|
||||
inherit (types)
|
||||
submodule
|
||||
attrsOf
|
||||
str
|
||||
;
|
||||
|
||||
evalInventory =
|
||||
m:
|
||||
(evalModules {
|
||||
# Static modules
|
||||
modules = [
|
||||
../../inventory/build-inventory/interface.nix
|
||||
{
|
||||
modules.test = {};
|
||||
}
|
||||
m
|
||||
];
|
||||
}).config;
|
||||
|
||||
flakeFixture = { inputs = {}; };
|
||||
|
||||
callInventoryAdapter = inventoryModule: import ../inventory-adapter.nix { inherit lib; flake = flakeFixture; inventory = evalInventory inventoryModule; };
|
||||
in
|
||||
{
|
||||
test_simple =
|
||||
let res = callInventoryAdapter {
|
||||
# Authored module
|
||||
# A minimal module looks like this
|
||||
# It isn't exactly doing anything but it's a valid module that produces an output
|
||||
modules."simple-module" = {
|
||||
_class = "clan.service";
|
||||
manifest = {
|
||||
name = "netwitness";
|
||||
};
|
||||
};
|
||||
# User config
|
||||
instances."instance_foo" = {
|
||||
module = {
|
||||
name = "simple-module";
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
# Test that the module is mapped into the output
|
||||
# We might change the attribute name in the future
|
||||
expr = res.evals ? "self-simple-module";
|
||||
expected = true;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user