From bd0d6e9d6fa0c481a87b52a676d2af9b1a98e555 Mon Sep 17 00:00:00 2001 From: zahrasidhpuri-crest Date: Wed, 1 Apr 2020 11:04:43 +0530 Subject: [PATCH 1/6] ACD-4056: Merged the test case no dash and not empty in one --- .../standard_lib/addon_basic.py | 55 +++---------------- 1 file changed, 8 insertions(+), 47 deletions(-) diff --git a/pytest_splunk_addon/standard_lib/addon_basic.py b/pytest_splunk_addon/standard_lib/addon_basic.py index 5d5a1a24c..ea1e1b360 100644 --- a/pytest_splunk_addon/standard_lib/addon_basic.py +++ b/pytest_splunk_addon/standard_lib/addon_basic.py @@ -108,7 +108,7 @@ def test_props_fields( assert result @pytest.mark.splunk_addon_searchtime - def test_props_fields_no_dash( + def test_props_fields_no_dash_not_empty( self, splunk_search_util, splunk_app_fields, record_property, caplog ): """ @@ -136,60 +136,21 @@ def test_props_fields_no_dash( ) op = "" for f in splunk_app_fields["fields"]: - search = search + f' {op} {f}="-"' + search = search + f' {op} {f}="-" OR {f}=""' op = "OR" search = search + ")" self.logger.debug(f"Executing the search query: {search}") # run search - result = splunk_search_util.checkQueryCountIsGreaterThanZero( - search, interval=INTERVAL, retries=RETRIES - ) - record_property("search", search) - - assert not result - - @pytest.mark.splunk_addon_searchtime - def test_props_fields_no_empty( - self, splunk_search_util, splunk_app_fields, record_property, caplog - ): - """ - Test case to check props property mentioned in props.conf - - This test case checks negative scenario for field blank value. - Args: - splunk_search_util(SearchUtil): - Object that helps to search on Splunk. - splunk_app_fields(fixture): - Test for stanza field. - record_property(fixture): - Document facts of test cases. - caplog : - fixture to capture logs. - """ - record_property("stanza_name", splunk_app_fields["stanza_name"]) - record_property("stanza_type", splunk_app_fields["stanza_type"]) - record_property("fields", splunk_app_fields["fields"]) - - search = ( - f"search (index=_internal OR index=*)" - f" {splunk_app_fields['stanza_type']}=" - f"{splunk_app_fields['stanza_name']} AND (" - ) - op = "" - for f in splunk_app_fields["fields"]: - search = search + f' {op} {f}=""' - op = "OR" - search = search + ")" + result, results = splunk_search_util.checkQueryCountIsZero(search) - self.logger.debug(f"Executing the search query: {search}") - # run search - result = splunk_search_util.checkQueryCountIsGreaterThanZero( - search, interval=INTERVAL, retries=RETRIES - ) + if not result: + record_property("results", results.as_list) + pp = pprint.PrettyPrinter(indent=4) + pp.pprint(results.as_list[-10:]) record_property("search", search) + assert result - assert not result # This test will check if there is at least one event with specified tags @pytest.mark.splunk_addon_searchtime From 10db9c429af1bfb22efc2677660308121d51e97f Mon Sep 17 00:00:00 2001 From: zahrasidhpuri-crest Date: Wed, 1 Apr 2020 11:33:48 +0530 Subject: [PATCH 2/6] ACD-4056: Resolve test case failure --- tests/test_splunk_addon.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_splunk_addon.py b/tests/test_splunk_addon.py index 370f6dd6e..f3fd9135d 100644 --- a/tests/test_splunk_addon.py +++ b/tests/test_splunk_addon.py @@ -136,7 +136,7 @@ def empty_method(): "\n".join(result.stdout.lines), "\n".join(result.stderr.lines), ) - result.assert_outcomes(passed=294, failed=0) + result.assert_outcomes(passed=195, failed=0) # make sure that that we get a '0' exit code for the testsuite assert result.ret == 0 @@ -186,7 +186,7 @@ def empty_method(): "\n".join(result.stdout.lines), "\n".join(result.stderr.lines), ) - result.assert_outcomes(passed=99, failed=31) + result.assert_outcomes(passed=55, failed=33) # The test suite should fail as this is a negative test assert result.ret != 0 From 819cf967c50235af79956303b86b8fe009521f4e Mon Sep 17 00:00:00 2001 From: zahrasidhpuri-crest Date: Wed, 1 Apr 2020 12:52:09 +0530 Subject: [PATCH 3/6] ACD-4056:Updated variable names --- pytest_splunk_addon/standard_lib/addon_basic.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pytest_splunk_addon/standard_lib/addon_basic.py b/pytest_splunk_addon/standard_lib/addon_basic.py index ea1e1b360..d85474f1a 100644 --- a/pytest_splunk_addon/standard_lib/addon_basic.py +++ b/pytest_splunk_addon/standard_lib/addon_basic.py @@ -134,10 +134,10 @@ def test_props_fields_no_dash_not_empty( f" {splunk_app_fields['stanza_type']}=" f"{splunk_app_fields['stanza_name']} AND (" ) - op = "" - for f in splunk_app_fields["fields"]: - search = search + f' {op} {f}="-" OR {f}=""' - op = "OR" + operator = "" + for field in splunk_app_fields["fields"]: + search = search + f' {operator} {field}="-" OR {field}=""' + operator = "OR" search = search + ")" self.logger.debug(f"Executing the search query: {search}") From 11f4b9fbcd0f2ca63a283f70d26b030fb2f8495c Mon Sep 17 00:00:00 2001 From: zahrasidhpuri-crest Date: Wed, 1 Apr 2020 13:11:35 +0530 Subject: [PATCH 4/6] ACD-4056: Update variable name --- pytest_splunk_addon/standard_lib/addon_basic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytest_splunk_addon/standard_lib/addon_basic.py b/pytest_splunk_addon/standard_lib/addon_basic.py index d85474f1a..48c484c34 100644 --- a/pytest_splunk_addon/standard_lib/addon_basic.py +++ b/pytest_splunk_addon/standard_lib/addon_basic.py @@ -95,8 +95,8 @@ def test_props_fields( f" {splunk_app_fields['stanza_type']}=" f"{splunk_app_fields['stanza_name']}" ) - for f in splunk_app_fields["fields"]: - search = search + f' AND ({f}=* AND NOT {f}="-" AND NOT {f}="")' + for field in splunk_app_fields["fields"]: + search = search + f' AND ({field}=* AND NOT {field}="-" AND NOT {field}="")' self.logger.debug(f"Executing the search query: {search}") # run search From 62fecffdc7bad5da33841aa5f33fcc3a3957439d Mon Sep 17 00:00:00 2001 From: zahrasidhpuri-crest Date: Wed, 1 Apr 2020 20:17:57 +0530 Subject: [PATCH 5/6] ACD-4056: Updated search query --- pytest_splunk_addon/standard_lib/addon_basic.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pytest_splunk_addon/standard_lib/addon_basic.py b/pytest_splunk_addon/standard_lib/addon_basic.py index 48c484c34..ba431d558 100644 --- a/pytest_splunk_addon/standard_lib/addon_basic.py +++ b/pytest_splunk_addon/standard_lib/addon_basic.py @@ -132,13 +132,12 @@ def test_props_fields_no_dash_not_empty( search = ( f"search (index=_internal OR index=*)" f" {splunk_app_fields['stanza_type']}=" - f"{splunk_app_fields['stanza_name']} AND (" + f"{splunk_app_fields['stanza_name']} AND " ) operator = "" for field in splunk_app_fields["fields"]: - search = search + f' {operator} {field}="-" OR {field}=""' - operator = "OR" - search = search + ")" + search = search + f'{operator} ( {field}="-" OR {field}="") ' + operator = "OR") self.logger.debug(f"Executing the search query: {search}") # run search From 28c0ac7fcccd2b6b69442b7a229806f82248dc3d Mon Sep 17 00:00:00 2001 From: zahrasidhpuri-crest Date: Wed, 1 Apr 2020 20:46:07 +0530 Subject: [PATCH 6/6] ACD-4056: Fix test case failure --- pytest_splunk_addon/standard_lib/addon_basic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest_splunk_addon/standard_lib/addon_basic.py b/pytest_splunk_addon/standard_lib/addon_basic.py index ba431d558..4eae1dd75 100644 --- a/pytest_splunk_addon/standard_lib/addon_basic.py +++ b/pytest_splunk_addon/standard_lib/addon_basic.py @@ -137,7 +137,7 @@ def test_props_fields_no_dash_not_empty( operator = "" for field in splunk_app_fields["fields"]: search = search + f'{operator} ( {field}="-" OR {field}="") ' - operator = "OR") + operator = "OR" self.logger.debug(f"Executing the search query: {search}") # run search