feat(inventory/instances): prevent modules without explizit class from beeing used
This commit is contained in:
@@ -22,6 +22,15 @@ let
|
||||
}).config;
|
||||
|
||||
flakeInputsFixture = {
|
||||
# Example upstream module
|
||||
upstream.clan.modules = {
|
||||
uzzi = {
|
||||
_class = "clan.service";
|
||||
manifest = {
|
||||
name = "uzzi-from-upstream";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
callInventoryAdapter =
|
||||
@@ -32,6 +41,7 @@ let
|
||||
};
|
||||
in
|
||||
{
|
||||
resolve_module_spec = import ./import_module_spec.nix { inherit lib callInventoryAdapter; };
|
||||
test_simple =
|
||||
let
|
||||
res = callInventoryAdapter {
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
{ callInventoryAdapter }:
|
||||
let
|
||||
# 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."A" = {
|
||||
_class = "clan.service";
|
||||
manifest = {
|
||||
name = "network";
|
||||
};
|
||||
};
|
||||
|
||||
modules."B" =
|
||||
{ ... }:
|
||||
{
|
||||
options.stuff = "legacy-clan-service";
|
||||
};
|
||||
|
||||
machines = {
|
||||
jon = { };
|
||||
sara = { };
|
||||
};
|
||||
|
||||
resolve =
|
||||
spec:
|
||||
callInventoryAdapter {
|
||||
inherit modules machines;
|
||||
instances."instance_foo" = {
|
||||
module = spec;
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
test_import_local_module_by_name = {
|
||||
expr = (resolve { name = "A"; }).importedModuleWithInstances.instance_foo.resolvedModule;
|
||||
expected = {
|
||||
_class = "clan.service";
|
||||
manifest = {
|
||||
name = "network";
|
||||
};
|
||||
};
|
||||
};
|
||||
test_import_remote_module_by_name = {
|
||||
expr =
|
||||
(resolve {
|
||||
name = "uzzi";
|
||||
input = "upstream";
|
||||
}).importedModuleWithInstances.instance_foo.resolvedModule;
|
||||
expected = {
|
||||
_class = "clan.service";
|
||||
manifest = {
|
||||
name = "uzzi-from-upstream";
|
||||
};
|
||||
};
|
||||
};
|
||||
# Currently this should fail
|
||||
# TODO: Can we implement a default wrapper to make migration easy?
|
||||
test_import_local_legacy_module = {
|
||||
expr = (resolve { name = "B"; }).allMachines;
|
||||
expectedError = {
|
||||
type = "ThrownError";
|
||||
msg = "Module 'B' is not a valid 'clan.service' module.*";
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user