Skip to content

Commit

Permalink
fix: globalConfig validator respects numbers in values in autoComplet…
Browse files Browse the repository at this point in the history
…eFields (#957)

* fix: globalConfig validator respects numbers in values in autoCompleteFields

* fix: globalConfig validator respects numbers in values in autoCompleteFields.children
  • Loading branch information
artemrys authored Nov 27, 2023
1 parent de74f1a commit 1716494
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 3 deletions.
12 changes: 10 additions & 2 deletions splunk_add_on_ucc_framework/global_config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ def _validate_children_duplicates(
labels, values = [], []
for child in children:
labels.append(child["label"].lower())
values.append(child["value"].lower())
child_value = child["value"]
if isinstance(child_value, str):
values.append(child_value.lower())
else:
values.append(child_value)
if self._find_duplicates_in_list(values) or self._find_duplicates_in_list(
labels
):
Expand All @@ -273,7 +277,11 @@ def _validate_autoCompleteFields_duplicates(
if children:
self._validate_children_duplicates(children, entity_label)
else:
values.append(field.get("value").lower())
field_value = field.get("value")
if isinstance(field_value, str):
values.append(field_value.lower())
else:
values.append(field_value)
if self._find_duplicates_in_list(values) or self._find_duplicates_in_list(
labels
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@
"meta": {
"name": "Splunk_TA_UCCExample",
"restRoot": "splunk_ta_uccexample",
"version": "5.32.0Rf6551a7f",
"version": "5.32.0Rde74f1a8",
"displayName": "Splunk UCC test Add-on",
"schemaVersion": "0.0.3"
}
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/test_global_config_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,32 @@ def test_config_validation_when_valid(filename, is_yaml):
validator.validate()


def test_autocompletefields_support_integer_values():
# Regression unit test: https://github.com/splunk/addonfactory-ucc-generator/issues/794
global_config_path = helpers.get_testdata_file_path(
"invalid_config_configuration_autoCompleteFields_integer_values.json"
)
global_config = global_config_lib.GlobalConfig(global_config_path, False)

validator = GlobalConfigValidator(helpers.get_path_to_source_dir(), global_config)

with does_not_raise():
validator.validate()


def test_autocompletefields_children_support_integer_values():
# Regression unit test: https://github.com/splunk/addonfactory-ucc-generator/issues/794
global_config_path = helpers.get_testdata_file_path(
"invalid_config_configuration_autoCompleteFields_children_integer_values.json"
)
global_config = global_config_lib.GlobalConfig(global_config_path, False)

validator = GlobalConfigValidator(helpers.get_path_to_source_dir(), global_config)

with does_not_raise():
validator.validate()


def test_config_validation_when_deprecated_placeholder_is_used(caplog):
global_config_path = helpers.get_testdata_file_path(
"valid_config_deprecated_placeholder_usage.json"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"pages": {
"configuration": {
"tabs": [
{
"name": "logging",
"entity": [
{
"type": "singleSelect",
"label": "Label",
"options": {
"disableSearch": true,
"autoCompleteFields": [
{
"label": "Label group 1",
"children": [
{
"value": 1,
"label": "Label 1"
},
{
"value": 2,
"label": "Label 2"
},
{
"value": 3,
"label": "Label 3"
}
]
},
{
"label": "Label group 2",
"children": [
{
"value": 4,
"label": "Label 4"
},
{
"value": 5,
"label": "Label 5"
}
]
}
]
},
"defaultValue": 1,
"field": "loglevel"
}
],
"title": "Logging"
}
],
"title": "Configuration",
"description": "Set up your add-on"
}
},
"meta": {
"name": "Splunk_TA_UCCExample",
"restRoot": "splunk_ta_uccexample",
"version": "1.0.0",
"displayName": "Splunk UCC test Add-on",
"schemaVersion": "0.0.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"pages": {
"configuration": {
"tabs": [
{
"name": "logging",
"entity": [
{
"type": "singleSelect",
"label": "Label",
"options": {
"disableSearch": true,
"autoCompleteFields": [
{
"value": 1,
"label": "Label 1"
},
{
"value": 2,
"label": "Label 2"
},
{
"value": 3,
"label": "Label 3"
}
]
},
"defaultValue": 1,
"field": "loglevel"
}
],
"title": "Logging"
}
],
"title": "Configuration",
"description": "Set up your add-on"
}
},
"meta": {
"name": "Splunk_TA_UCCExample",
"restRoot": "splunk_ta_uccexample",
"version": "1.0.0",
"displayName": "Splunk UCC test Add-on",
"schemaVersion": "0.0.3"
}
}

0 comments on commit 1716494

Please sign in to comment.