clan-core/lib/jsonschema/test_parseOptions.nix

39 lines
945 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; },
}:
{
testParseOptions = {
expr = slib.parseModule ./example-interface.nix;
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 = {
additionalProperties = false;
2023-08-09 16:19:36 +00:00
properties = {
foo = {
additionalProperties = false;
2023-08-09 16:19:36 +00:00
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";
};
};
}