Skip to content

Commit

Permalink
tests: added test cases for enable action (#1454)
Browse files Browse the repository at this point in the history
**Issue number:**

## Summary
Added unit test cases for enable action in table inputs

### Changes

> Added unit test case regarding enable action in
`global_config_update.py` file.

### User experience

> No change in user experience

## Checklist

If your change doesn't seem to apply, please leave them unchecked.

* [x] I have performed a self-review of this change
* [x] Changes have been tested
* [ ] Changes are documented
* [x] PR title follows [conventional commit
semantics](https://www.conventionalcommits.org/en/v1.0.0/)
  • Loading branch information
hetangmodi-crest authored Nov 13, 2024
1 parent 8793cef commit 62d8ff5
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/unit/test_global_config_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
_dump_with_migrated_tabs,
_dump_with_migrated_entities,
_stop_build_on_placeholder_usage,
_dump_enable_from_global_config,
)
from splunk_add_on_ucc_framework.entity import IntervalEntity
from splunk_add_on_ucc_framework import global_config as global_config_lib
Expand Down Expand Up @@ -207,3 +208,31 @@ def test_config_validation_when_placeholder_is_present(tmp_path, caplog):
expected_schema_version = "0.0.7"
assert expected_schema_version == global_config.schema_version
assert error_log in caplog.text


def test_dump_enable_from_global_config_enable_present(tmp_path, caplog):
tmp_file_gc = tmp_path / "globalConfig.json"

helpers.copy_testdata_gc_to_tmp_file(
tmp_file_gc, "valid_config_input_with_enable_action.json"
)
global_config = global_config_lib.GlobalConfig(str(tmp_file_gc))
expected_schema_version = "0.0.9"

_dump_enable_from_global_config(global_config)

assert expected_schema_version == global_config.schema_version
assert "`enable` attribute found in input's page table action." in caplog.text


def test_dump_enable_from_global_config_enable_absent(tmp_path, caplog):
tmp_file_gc = tmp_path / "globalConfig.yaml"

helpers.copy_testdata_gc_to_tmp_file(tmp_file_gc, "valid_config.yaml")
global_config = global_config_lib.GlobalConfig(str(tmp_file_gc))
expected_schema_version = "0.0.9"

_dump_enable_from_global_config(global_config)

assert expected_schema_version == global_config.schema_version
assert caplog.text == ""
107 changes: 107 additions & 0 deletions tests/unit/testdata/valid_config_input_with_enable_action.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"pages": {
"configuration": {
"tabs": [
{
"type": "LoggingTab"
}
],
"title": "Configuration",
"description": "Set up your add-on"
},
"inputs": {
"services": [
{
"name": "example_input_ten",
"entity": [
{
"type": "text",
"label": "Name",
"validators": [
{
"type": "regex",
"errorMsg": "Input Name must begin with a letter and consist exclusively of alphanumeric characters and underscores.",
"pattern": "^[a-zA-Z]\\w*$"
},
{
"type": "string",
"errorMsg": "Length of input name should be between 1 and 100",
"minLength": 1,
"maxLength": 100
}
],
"field": "name",
"help": "A unique name for the data input.",
"required": true
},
{
"type": "interval",
"field": "interval",
"label": "Interval",
"help": "Time interval of the data input, in seconds.",
"required": true
}
],
"title": "Example Input Three"
}
],
"title": "Inputs",
"description": "Manage your data inputs",
"table": {
"actions": [
"edit",
"delete",
"clone",
"enable"
],
"header": [
{
"label": "Name",
"field": "name"
},
{
"label": "Interval",
"field": "interval"
},
{
"label": "Index",
"field": "index"
},
{
"label": "Status",
"field": "disabled"
}
],
"moreInfo": [
{
"label": "Name",
"field": "name"
},
{
"label": "Interval",
"field": "interval"
},
{
"label": "Index",
"field": "index"
},
{
"label": "Status",
"field": "disabled",
"mapping": {
"true": "Disabled",
"false": "Enabled"
}
}
]
}
}
},
"meta": {
"name": "Splunk_TA_UCCExample",
"restRoot": "splunk_ta_uccexample",
"version": "1.0.0",
"displayName": "Splunk UCC test Add-on",
"schemaVersion": "0.0.8"
}
}

0 comments on commit 62d8ff5

Please sign in to comment.