2023-08-02 18:04:16 +00:00
|
|
|
# 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; },
|
2023-08-02 18:04:16 +00:00
|
|
|
}:
|
|
|
|
let
|
|
|
|
evaledOptions =
|
|
|
|
let
|
2024-03-17 18:48:49 +00:00
|
|
|
evaledConfig = lib.evalModules { modules = [ ./example-interface.nix ]; };
|
2023-08-02 18:04:16 +00:00
|
|
|
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";
|
|
|
|
};
|
|
|
|
};
|
2023-08-02 18:04:16 +00:00
|
|
|
}
|