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
|
|
|
}:
|
|
|
|
{
|
|
|
|
testParseOptions = {
|
2024-06-24 14:00:46 +00:00
|
|
|
expr = slib.parseModule ./example-interface.nix;
|
2023-08-02 18:04:16 +00:00
|
|
|
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 = {
|
2024-06-24 13:55:48 +00:00
|
|
|
additionalProperties = false;
|
2023-08-09 16:19:36 +00:00
|
|
|
properties = {
|
|
|
|
foo = {
|
2024-06-24 13:55:48 +00:00
|
|
|
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";
|
|
|
|
};
|
|
|
|
};
|
2023-08-02 18:04:16 +00:00
|
|
|
}
|