Tests(deferred custom module): add more tests, dissallow nested imports
This commit is contained in:
@@ -2,18 +2,24 @@
|
||||
{
|
||||
uniqueDeferredSerializableModule = lib.fix (
|
||||
self:
|
||||
|
||||
let
|
||||
checkDef = loc: def: if def.value ? imports then throw "uniqueDeferredSerializableModule doesn't allow nested imports" else def;
|
||||
in
|
||||
# Essentially the "raw" type, but with a custom name and check
|
||||
lib.mkOptionType {
|
||||
name = "deferredModule";
|
||||
description = "deferred module that has custom check and merge behavior";
|
||||
description = "deferred custom module. Must be JSON serializable.";
|
||||
descriptionClass = "noun";
|
||||
# Unfortunately, tryEval doesn't catch JSON errors
|
||||
check = value: lib.seq (builtins.toJSON value) true;
|
||||
check = value: lib.seq (builtins.toJSON value) (lib.isAttrs value);
|
||||
merge = lib.options.mergeUniqueOption {
|
||||
message = "------";
|
||||
merge = loc: defs: {
|
||||
imports = map (
|
||||
def: lib.setDefaultModuleLocation "${def.file}, via option ${lib.showOption loc}" def.value
|
||||
def:
|
||||
lib.seq (checkDef loc def)
|
||||
lib.setDefaultModuleLocation "${def.file}, via option ${lib.showOption loc}" def.value
|
||||
) defs;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ let
|
||||
};
|
||||
in
|
||||
{
|
||||
test_1 =
|
||||
test_simple =
|
||||
let
|
||||
eval = evalSettingsModule {
|
||||
foo = { };
|
||||
@@ -38,4 +38,53 @@ in
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
test_no_nested_imports =
|
||||
let
|
||||
eval = evalSettingsModule {
|
||||
foo = {
|
||||
imports = [];
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit eval;
|
||||
expr = eval.config.foo;
|
||||
expectedError = {
|
||||
type = "ThrownError";
|
||||
message = "*nested imports";
|
||||
};
|
||||
};
|
||||
|
||||
test_no_function_modules =
|
||||
let
|
||||
eval = evalSettingsModule {
|
||||
foo = {...}: {
|
||||
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit eval;
|
||||
expr = eval.config.foo;
|
||||
expectedError = {
|
||||
type = "TypeError";
|
||||
message = "cannot convert a function to JSON";
|
||||
};
|
||||
};
|
||||
|
||||
test_non_attrs_module =
|
||||
let
|
||||
eval = evalSettingsModule {
|
||||
foo = "foo.nix";
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit eval;
|
||||
expr = eval.config.foo;
|
||||
expectedError = {
|
||||
type = "ThrownError";
|
||||
message = ".*foo.* is not of type";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user