Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 14 additions & 54 deletions pytest_splunk_addon/standard_lib/addon_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
):
"""
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_splunk_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down