clan-core/lib/jsonschema/test_parseOptions.nix

44 lines
1003 B
Nix
Raw Normal View History

# tests for the nixos options to jsonschema converter
# run these tests via `nix-unit ./test.nix`
2024-03-17 18:48:49 +00:00
{
lib ? (import <nixpkgs> { }).lib,
slib ? import ./. { inherit lib; },
}:
let
evaledOptions =
let
2024-03-17 18:48:49 +00:00
evaledConfig = lib.evalModules { modules = [ ./example-interface.nix ]; };
in
evaledConfig.options;
in
{
testParseOptions = {
expr = slib.parseOptions evaledOptions;
expected = builtins.fromJSON (builtins.readFile ./example-schema.json);
};
2023-08-09 16:19:36 +00:00
testParseNestedOptions =
let
evaled = lib.evalModules {
2024-03-17 18:48:49 +00:00
modules = [ { options.foo.bar = lib.mkOption { type = lib.types.bool; }; } ];
2023-08-09 16:19:36 +00:00
};
in
{
expr = slib.parseOptions evaled.options;
expected = {
properties = {
foo = {
properties = {
2024-03-17 18:48:49 +00:00
bar = {
type = "boolean";
};
2023-08-09 16:19:36 +00:00
};
required = [ "bar" ];
type = "object";
};
};
type = "object";
};
};
}