From e9e75c0d645d5eb76ec020e11acbd517b3c3bd41 Mon Sep 17 00:00:00 2001 From: Artem Rys Date: Sat, 7 Aug 2021 15:21:27 +0200 Subject: [PATCH] test: add test for configuration only add-on --- .../package/README.txt | 1 + .../package/app.manifest | 51 +++++++++++++++++++ .../package/default/app.conf | 23 +++++++++ .../package/default/eventtypes.conf | 2 + .../package/default/props.conf | 4 ++ .../package/default/tags.conf | 2 + tests/data/test_ucc_generate.py | 38 ++++++++++++++ .../Splunk_TA_UCCExample/README.txt | 1 + .../Splunk_TA_UCCExample/VERSION | 2 + .../Splunk_TA_UCCExample/app.manifest | 51 +++++++++++++++++++ .../Splunk_TA_UCCExample/default/app.conf | 27 ++++++++++ .../default/eventtypes.conf | 2 + .../Splunk_TA_UCCExample/default/props.conf | 4 ++ .../Splunk_TA_UCCExample/default/tags.conf | 2 + 14 files changed, 210 insertions(+) create mode 100644 tests/data/package_no_global_config/package/README.txt create mode 100644 tests/data/package_no_global_config/package/app.manifest create mode 100644 tests/data/package_no_global_config/package/default/app.conf create mode 100644 tests/data/package_no_global_config/package/default/eventtypes.conf create mode 100644 tests/data/package_no_global_config/package/default/props.conf create mode 100644 tests/data/package_no_global_config/package/default/tags.conf create mode 100644 tests/expected_output_no_global_config/Splunk_TA_UCCExample/README.txt create mode 100644 tests/expected_output_no_global_config/Splunk_TA_UCCExample/VERSION create mode 100644 tests/expected_output_no_global_config/Splunk_TA_UCCExample/app.manifest create mode 100644 tests/expected_output_no_global_config/Splunk_TA_UCCExample/default/app.conf create mode 100644 tests/expected_output_no_global_config/Splunk_TA_UCCExample/default/eventtypes.conf create mode 100644 tests/expected_output_no_global_config/Splunk_TA_UCCExample/default/props.conf create mode 100644 tests/expected_output_no_global_config/Splunk_TA_UCCExample/default/tags.conf diff --git a/tests/data/package_no_global_config/package/README.txt b/tests/data/package_no_global_config/package/README.txt new file mode 100644 index 000000000..530a9e548 --- /dev/null +++ b/tests/data/package_no_global_config/package/README.txt @@ -0,0 +1 @@ +Just a readme \ No newline at end of file diff --git a/tests/data/package_no_global_config/package/app.manifest b/tests/data/package_no_global_config/package/app.manifest new file mode 100644 index 000000000..6bcf830b8 --- /dev/null +++ b/tests/data/package_no_global_config/package/app.manifest @@ -0,0 +1,51 @@ +{ + "schemaVersion": "2.0.0", + "info": { + "title": "Splunk Add-on for UCC Example", + "id": { + "group": null, + "name": "Splunk_TA_UCCExample", + "version": "7.0.1" + }, + "author": [ + { + "name": "Splunk", + "email": null, + "company": null + } + ], + "releaseDate": null, + "description": "Splunk Add-on for UCC Example", + "classification": { + "intendedAudience": null, + "categories": [], + "developmentStatus": null + }, + "commonInformationModels": null, + "license": { + "name": null, + "text": "LICENSES/Apache-2.0.txt", + "uri": null + }, + "privacyPolicy": { + "name": null, + "text": null, + "uri": null + }, + "releaseNotes": { + "name": null, + "text": "./README.txt", + "uri": null + } + }, + "dependencies": null, + "tasks": null, + "inputGroups": null, + "incompatibleApps": null, + "platformRequirements": null, + "supportedDeployments": [ + "_standalone", + "_distributed" + ], + "targetWorkloads": null +} diff --git a/tests/data/package_no_global_config/package/default/app.conf b/tests/data/package_no_global_config/package/default/app.conf new file mode 100644 index 000000000..af80bbf04 --- /dev/null +++ b/tests/data/package_no_global_config/package/default/app.conf @@ -0,0 +1,23 @@ +###################################################### +# +# ${package.name} +# +# ${copyright} +# +###################################################### + +[install] +build = 0 + +[launcher] +author = Splunk Inc. +version = 0.1.0 +description = Splunk_TA_UCCExample + +[ui] +is_visible = true +label = Splunk_TA_UCCExample +docs_section_override=AddOns:released + +[package] +id = Splunk_TA_UCCExample diff --git a/tests/data/package_no_global_config/package/default/eventtypes.conf b/tests/data/package_no_global_config/package/default/eventtypes.conf new file mode 100644 index 000000000..bd34af462 --- /dev/null +++ b/tests/data/package_no_global_config/package/default/eventtypes.conf @@ -0,0 +1,2 @@ +[new_eventtype] +search = sourcetype=new_sourcetype \ No newline at end of file diff --git a/tests/data/package_no_global_config/package/default/props.conf b/tests/data/package_no_global_config/package/default/props.conf new file mode 100644 index 000000000..9527f0dc3 --- /dev/null +++ b/tests/data/package_no_global_config/package/default/props.conf @@ -0,0 +1,4 @@ +# props.conf + +[new_sourcetype] +EVAL-new_field = if(field2 = "hello", "world") \ No newline at end of file diff --git a/tests/data/package_no_global_config/package/default/tags.conf b/tests/data/package_no_global_config/package/default/tags.conf new file mode 100644 index 000000000..2dfd39e0e --- /dev/null +++ b/tests/data/package_no_global_config/package/default/tags.conf @@ -0,0 +1,2 @@ +[eventtype=new_eventtype] +new_tag = enabled \ No newline at end of file diff --git a/tests/data/test_ucc_generate.py b/tests/data/test_ucc_generate.py index 5b0f727bd..faa454269 100644 --- a/tests/data/test_ucc_generate.py +++ b/tests/data/test_ucc_generate.py @@ -122,6 +122,44 @@ def test_ucc_generate_with_configuration(self): msg=f"Expected file {expected_file_path} is different from {actual_file_path}", ) + def test_ucc_generate_with_configuration_files_only(self): + with tempfile.TemporaryDirectory() as temp_dir: + package_folder = path.join( + path.dirname(path.realpath(__file__)), + "package_no_global_config", + "package", + ) + ucc.generate(source=package_folder, outputdir=temp_dir) + + expected_folder = path.join( + path.dirname(__file__), + "..", + "expected_output_no_global_config", + "Splunk_TA_UCCExample", + ) + actual_folder = path.join(temp_dir, "Splunk_TA_UCCExample") + + # app.manifest and appserver/static/js/build/globalConfig.json + # should be included too, but they may introduce flaky tests as + # their content depends on the git commit. + # Expected add-on package folder does not have "lib" in it. + files_to_be_equal = [ + ("README.txt",), + ("default", "eventtypes.conf"), + ("default", "props.conf"), + ("default", "tags.conf"), + ] + for f in files_to_be_equal: + expected_file_path = path.join(expected_folder, *f) + actual_file_path = path.join(actual_folder, *f) + self.assertTrue( + assert_identical_files( + expected_file_path, + actual_file_path, + ), + msg=f"Expected file {expected_file_path} is different from {actual_file_path}", + ) + if __name__ == "__main__": unittest.main() diff --git a/tests/expected_output_no_global_config/Splunk_TA_UCCExample/README.txt b/tests/expected_output_no_global_config/Splunk_TA_UCCExample/README.txt new file mode 100644 index 000000000..530a9e548 --- /dev/null +++ b/tests/expected_output_no_global_config/Splunk_TA_UCCExample/README.txt @@ -0,0 +1 @@ +Just a readme \ No newline at end of file diff --git a/tests/expected_output_no_global_config/Splunk_TA_UCCExample/VERSION b/tests/expected_output_no_global_config/Splunk_TA_UCCExample/VERSION new file mode 100644 index 000000000..08a4a7a4d --- /dev/null +++ b/tests/expected_output_no_global_config/Splunk_TA_UCCExample/VERSION @@ -0,0 +1,2 @@ +1.0.0 +1.0.0 \ No newline at end of file diff --git a/tests/expected_output_no_global_config/Splunk_TA_UCCExample/app.manifest b/tests/expected_output_no_global_config/Splunk_TA_UCCExample/app.manifest new file mode 100644 index 000000000..240da934b --- /dev/null +++ b/tests/expected_output_no_global_config/Splunk_TA_UCCExample/app.manifest @@ -0,0 +1,51 @@ +{ + "dependencies": null, + "incompatibleApps": null, + "info": { + "author": [ + { + "company": null, + "email": null, + "name": "Splunk" + } + ], + "classification": { + "categories": [], + "developmentStatus": null, + "intendedAudience": null + }, + "commonInformationModels": null, + "description": "Splunk Add-on for UCC Example", + "id": { + "group": null, + "name": "Splunk_TA_UCCExample", + "version": "1.0.0" + }, + "license": { + "name": null, + "text": "LICENSES/Apache-2.0.txt", + "uri": null + }, + "privacyPolicy": { + "name": null, + "text": null, + "uri": null + }, + "releaseDate": null, + "releaseNotes": { + "name": null, + "text": "./README.txt", + "uri": null + }, + "title": "Splunk Add-on for UCC Example" + }, + "inputGroups": null, + "platformRequirements": null, + "schemaVersion": "2.0.0", + "supportedDeployments": [ + "_standalone", + "_distributed" + ], + "targetWorkloads": null, + "tasks": null +} \ No newline at end of file diff --git a/tests/expected_output_no_global_config/Splunk_TA_UCCExample/default/app.conf b/tests/expected_output_no_global_config/Splunk_TA_UCCExample/default/app.conf new file mode 100644 index 000000000..de6d324a9 --- /dev/null +++ b/tests/expected_output_no_global_config/Splunk_TA_UCCExample/default/app.conf @@ -0,0 +1,27 @@ +###################################################### +# +# ${package.name} +# +# ${copyright} +# +###################################################### + +[install] +build = 1628341075 + +[launcher] +author = Splunk Inc. +version = 1.0.0 +description = Splunk Add-on for UCC Example + +[ui] +is_visible = true +label = Splunk Add-on for UCC Example +docs_section_override = AddOns:released + +[package] +id = Splunk_TA_UCCExample + +[id] +version = 1.0.0 + diff --git a/tests/expected_output_no_global_config/Splunk_TA_UCCExample/default/eventtypes.conf b/tests/expected_output_no_global_config/Splunk_TA_UCCExample/default/eventtypes.conf new file mode 100644 index 000000000..bd34af462 --- /dev/null +++ b/tests/expected_output_no_global_config/Splunk_TA_UCCExample/default/eventtypes.conf @@ -0,0 +1,2 @@ +[new_eventtype] +search = sourcetype=new_sourcetype \ No newline at end of file diff --git a/tests/expected_output_no_global_config/Splunk_TA_UCCExample/default/props.conf b/tests/expected_output_no_global_config/Splunk_TA_UCCExample/default/props.conf new file mode 100644 index 000000000..9527f0dc3 --- /dev/null +++ b/tests/expected_output_no_global_config/Splunk_TA_UCCExample/default/props.conf @@ -0,0 +1,4 @@ +# props.conf + +[new_sourcetype] +EVAL-new_field = if(field2 = "hello", "world") \ No newline at end of file diff --git a/tests/expected_output_no_global_config/Splunk_TA_UCCExample/default/tags.conf b/tests/expected_output_no_global_config/Splunk_TA_UCCExample/default/tags.conf new file mode 100644 index 000000000..2dfd39e0e --- /dev/null +++ b/tests/expected_output_no_global_config/Splunk_TA_UCCExample/default/tags.conf @@ -0,0 +1,2 @@ +[eventtype=new_eventtype] +new_tag = enabled \ No newline at end of file