diff --git a/splunk_add_on_ucc_framework/schema/schema.json b/splunk_add_on_ucc_framework/schema/schema.json index 67a986965..d2304217a 100644 --- a/splunk_add_on_ucc_framework/schema/schema.json +++ b/splunk_add_on_ucc_framework/schema/schema.json @@ -1,5 +1,5 @@ { - "$schema": "http://json-schema.org/draft-07/schema", + "$schema": "http://json-schema.org/draft-07/schema#", "definitions": { "AlertEntity": { "type": "object", @@ -176,7 +176,14 @@ "tabs": { "type": "array", "items": { - "$ref": "#/definitions/TabContent" + "anyOf": [ + { + "$ref": "#/definitions/TabContent" + }, + { + "$ref": "#/definitions/tabs/Logging" + } + ] }, "minItems": 1 } @@ -2208,6 +2215,46 @@ "$ref": "#/definitions/markdownMessagePlainText" } ] + }, + "tabs": { + "Logging": { + "type": "object", + "properties": { + "type": { + "type": "string", + "const": "loggingTab" + }, + "name": { + "type": "string", + "pattern": "^[\\/\\w]+$", + "maxLength": 250 + }, + "title": { + "type": "string", + "maxLength": 50 + }, + "label": { + "type": "string" + }, + "field": { + "$ref": "#/definitions/Field", + "default": "loglevel" + }, + "levels": { + "type": "array", + "items": { + "type": "string" + } + }, + "defaultLevel": { + "type": "string" + } + }, + "required": [ + "type" + ], + "additionalProperties": false + } } }, "type": "object", diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index c7c2b5858..397930553 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -1,3 +1,5 @@ +import json + import pytest from splunk_add_on_ucc_framework import global_config as global_config_lib @@ -12,6 +14,12 @@ def app_manifest_correct() -> app_manifest_lib.AppManifest: return app_manifest +@pytest.fixture +def global_config_all_json_content(): + with open(helpers.get_testdata_file_path("valid_config.json")) as fp: + return json.load(fp) + + @pytest.fixture def global_config_all_json() -> global_config_lib.GlobalConfig: global_config_path = helpers.get_testdata_file_path("valid_config.json") diff --git a/tests/unit/test_schema.py b/tests/unit/test_schema.py new file mode 100644 index 000000000..0abf3bf26 --- /dev/null +++ b/tests/unit/test_schema.py @@ -0,0 +1,55 @@ +import functools +import json +from typing import Any, Dict +from pathlib import Path + +import jsonschema +import pytest + +from splunk_add_on_ucc_framework import __file__ as module_init_path + + +@pytest.fixture +def schema_path(): + return Path(module_init_path).parent / "schema" / "schema.json" + + +@pytest.fixture +def schema_json(schema_path): + with schema_path.open() as fp: + return json.load(fp) + + +@pytest.fixture +def schema_validate(schema_json): + return functools.partial(jsonschema.validate, schema=schema_json) + + +@pytest.fixture +def config(global_config_all_json_content): + class BetterDict(Dict[Any, Any]): + def with_tab(self, tab): + self["pages"]["configuration"]["tabs"].append(tab) + return self + + return BetterDict(global_config_all_json_content) + + +def test_logging_component_short(schema_validate, config): + schema_validate(config.with_tab({"type": "loggingTab"})) + + +def test_logging_component_long(schema_validate, config): + schema_validate( + config.with_tab( + { + "type": "loggingTab", + "name": "logging", + "title": "Logging", + "label": "Log level", + "field": "loglevel", + "levels": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], + "defaultLevel": "INFO", + } + ) + )