Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: schema changes for LoggingTab #1099

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions splunk_add_on_ucc_framework/schema/schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"AlertEntity": {
"type": "object",
Expand Down Expand Up @@ -176,7 +176,14 @@
"tabs": {
"type": "array",
"items": {
"$ref": "#/definitions/TabContent"
"anyOf": [
{
"$ref": "#/definitions/TabContent"
},
{
"$ref": "#/definitions/components/Logging"
}
]
},
"minItems": 1
}
Expand Down Expand Up @@ -2208,6 +2215,46 @@
"$ref": "#/definitions/markdownMessagePlainText"
}
]
},
"components": {
"Logging": {
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "loggingComponent"
},
"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",
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

import pytest

from splunk_add_on_ucc_framework import global_config as global_config_lib
Expand All @@ -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")
Expand Down
55 changes: 55 additions & 0 deletions tests/unit/test_schema.py
Original file line number Diff line number Diff line change
@@ -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": "loggingComponent"}))


def test_logging_component_long(schema_validate, config):
schema_validate(
config.with_tab(
{
"type": "loggingComponent",
"name": "logging",
"title": "Logging",
"label": "Log level",
"field": "loglevel",
"levels": ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
"defaultLevel": "INFO",
}
)
)
Loading