diff --git a/pytest_splunk_addon/standard_lib/addon_basic.py b/pytest_splunk_addon/standard_lib/addon_basic.py index 5d5a1a24c..4eae1dd75 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 @@ -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 ): """ @@ -132,64 +132,24 @@ def test_props_fields_no_dash( 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 " ) - op = "" - for f in splunk_app_fields["fields"]: - search = search + f' {op} {f}="-"' - op = "OR" - search = search + ")" + operator = "" + for field in splunk_app_fields["fields"]: + search = search + f'{operator} ( {field}="-" OR {field}="") ' + operator = "OR" 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 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