Skip to content

Commit e4df4d6

Browse files
Merge pull request #228 from splunk/feature/savedsearch-tests
feat: Adds mechanism to generate tests by parsing savedsearches.conf.
2 parents 38f3e44 + 8e2584a commit e4df4d6

File tree

16 files changed

+298
-56
lines changed

16 files changed

+298
-56
lines changed

.github/workflows/cla.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
path-to-signatures: ".github/signatures/version1/cla.json"
2222
path-to-document: "https://github.com/splunk/addonfactory-test-releaseci/blob/main/CLA.md" # e.g. a CLA or a DCO document
2323
# branch should not be protected
24-
branch: "master"
24+
branch: "main"
2525
allowlist: dependabot
2626
#below are the optional inputs - If the optional inputs are not given, then default values will be taken
2727
#remote-organization-name: enter the remote organization name where the signatures should be stored (Default is storing the signatures in the same repository)

.github/workflows/release-notes.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
git fetch --prune --unshallow --tags
1616
- uses: snyk/[email protected]
1717
with:
18-
releaseBranch: master
18+
releaseBranch: main
1919
env:
2020
GITHUB_PR_USERNAME: ${{ github.actor }}
2121
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build.py

Lines changed: 0 additions & 46 deletions
This file was deleted.

docs/api_reference/addon_parser.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ TransformsParser
3434
.. automodule:: standard_lib.addon_parser.transforms_parser
3535
:members:
3636
:show-inheritance:
37+
38+
SavedsearchesParser
39+
~~~~~~~~~~~~~~~~~~~
40+
.. automodule:: standard_lib.addon_parser.savedsearches_parser
41+
:members:
42+
:show-inheritance:

docs/cim_tests.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Overview
77
The CIM tests are written with a purpose of testing the compatibility of the add-on with CIM Data Models (Based on Splunk_SA_CIM 4.15.0).
88
An add-on is said to be CIM compatible if it fulfils the following two criteria:
99

10-
1. The add-on extracts all the fields with valid values, which are marked as required by the `Data Model Definitions <https://github.com/splunk/pytest-splunk-addon/tree/master/pytest_splunk_addon/standard_lib/data_models>`_.
10+
1. The add-on extracts all the fields with valid values, which are marked as required by the `Data Model Definitions <https://github.com/splunk/pytest-splunk-addon/tree/main/pytest_splunk_addon/standard_lib/data_models>`_.
1111
2. Any event for the add-on is not mapped with more than one data model.
1212

1313
---------------------
@@ -34,7 +34,7 @@ Test Scenarios
3434
**Workflow:**
3535

3636
* Plugin parses tags.conf to get a list of tags for each eventtype.
37-
* Plugin parses all the `supported datamodels <https://github.com/splunk/pytest-splunk-addon/tree/master/pytest_splunk_addon/standard_lib/data_models>`_.
37+
* Plugin parses all the `supported datamodels <https://github.com/splunk/pytest-splunk-addon/tree/main/pytest_splunk_addon/standard_lib/data_models>`_.
3838
* Then it gets a list of the datasets mapped with an eventtype.
3939
* Generates test case for each eventtype.
4040

@@ -80,11 +80,11 @@ Test Scenarios
8080

8181
**Workflow:**
8282

83-
* Plugin collects the list of not_allowed_in_search fields from mapped datasets and `CommonFields.json <https://github.com/splunk/pytest-splunk-addon/blob/master/pytest_splunk_addon/standard_lib/cim_tests/CommonFields.json>`_.
83+
* Plugin collects the list of not_allowed_in_search fields from mapped datasets and `CommonFields.json <https://github.com/splunk/pytest-splunk-addon/blob/main/pytest_splunk_addon/standard_lib/cim_tests/CommonFields.json>`_.
8484
* Using search query the test case verifies if not_allowed_in_search fields are populated in search or not.
8585

8686
.. note::
87-
`CommonFields.json <https://github.com/splunk/pytest-splunk-addon/blob/master/pytest_splunk_addon/standard_lib/cim_tests/CommonFields.json>`_ contains fields which are automatically provided by asset and identity correlation features of applications like Splunk Enterprise Security.
87+
`CommonFields.json <https://github.com/splunk/pytest-splunk-addon/blob/main/pytest_splunk_addon/standard_lib/cim_tests/CommonFields.json>`_ contains fields which are automatically provided by asset and identity correlation features of applications like Splunk Enterprise Security.
8888

8989
**4. Testcase for all not_allowed_in_props fields**
9090

docs/field_tests.rst

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Overview
1515
5. Eval
1616
6. Eventtypes
1717
7. Tags
18+
8. Savedsearches
1819

1920
--------------------------------
2021

@@ -121,7 +122,21 @@ Test Scenarios
121122
**Workflow:**
122123

123124
* In tags.conf for each tag defined in the stanza, the plugin generates a test case.
124-
* For each tag, the plugin generates a search query including the stanza and the tag and asserts event_count > 0
125+
* For each tag, the plugin generates a search query including the stanza and the tag and asserts event_count > 0.
126+
127+
**7. Search query should be present in each savedsearches.**
128+
129+
.. code-block:: python
130+
131+
test_savedsearches[<savedsearch_stanza>]
132+
133+
Test case verifies that the search mentioned in savedsearch.conf generates valid search results.
134+
Here <savedsearch_stanza> is a stanza mentioned in savedsearches.conf file.
135+
136+
**Workflow:**
137+
138+
* In savedsearches.conf for each stanza, the plugin generates a test case.
139+
* For each stanza mentioned in savedsearches.conf plugin generates an SPL search query and asserts event_count > 0 for the savedsearch.
125140

126141
Testcase Troubleshooting
127142
------------------------

docs/how_to_use.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ Extending pytest-splunk-addon
279279

280280
How can this be achieved :
281281

282-
- Make json representation of the data models, which satisfies this `DataModelSchema <https://github.com/splunk/pytest-splunk-addon/blob/master/pytest_splunk_addon/standard_lib/cim_tests/DatamodelSchema.json>`_.
282+
- Make json representation of the data models, which satisfies this `DataModelSchema <https://github.com/splunk/pytest-splunk-addon/blob/main/pytest_splunk_addon/standard_lib/cim_tests/DatamodelSchema.json>`_.
283283
- Provide the path to the directory having all the data models by adding ``--splunk_dm_path path_to_dir`` to the pytest command
284-
- The test cases will now be generated for the data models provided to the plugin and not for the `default data models <https://github.com/splunk/pytest-splunk-addon/tree/master/pytest_splunk_addon/standard_lib/data_models>`_.
284+
- The test cases will now be generated for the data models provided to the plugin and not for the `default data models <https://github.com/splunk/pytest-splunk-addon/tree/main/pytest_splunk_addon/standard_lib/data_models>`_.
285285

286286
.. raw:: html
287287

docs/release_history.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,19 @@ Release History
88

99
The best way to track the development of pytest-splunk-addon is through `the GitHub Repo <https://github.com/splunk/pytest-splunk-addon/>`_.
1010

11-
1.3.14
11+
1.4.0
12+
""""""""""""""""""""""""""
13+
**Changes:**
14+
15+
* Plugin now generates and executes tests to validate savedsearches defined in savedsearches.conf.
16+
17+
**Known Issues:**
18+
19+
* Event ingestion through SC4S via UDP port
20+
* Fields for modular regular expressions are not extracted in the plugin.
21+
22+
23+
1.3.15
1224
""""""""""""""""""""""""""
1325
**Changes:**
1426

pytest_splunk_addon/plugin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ def pytest_configure(config):
3737
"markers",
3838
"splunk_searchtime_fields_eventtypes: Test search time eventtypes only",
3939
)
40+
config.addinivalue_line(
41+
"markers", "splunk_searchtime_fields_savedsearches: Test search time savedsearches only"
42+
)
4043
config.addinivalue_line(
4144
"markers", "splunk_searchtime_cim: Test CIM compatibility only"
4245
)

pytest_splunk_addon/standard_lib/addon_parser/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from .props_parser import PropsParser
1919
from .tags_parser import TagsParser
2020
from .eventtype_parser import EventTypeParser
21+
from .savedsearches_parser import SavedSearchParser
2122

2223
LOGGER = logging.getLogger("pytest-splunk-addon")
2324

@@ -37,6 +38,7 @@ def __init__(self, splunk_app_path):
3738
self._props_parser = None
3839
self._tags_parser = None
3940
self._eventtype_parser = None
41+
self._savedsearch_parser = None
4042

4143
@property
4244
def app(self):
@@ -62,6 +64,12 @@ def eventtype_parser(self):
6264
self._eventtype_parser = EventTypeParser(self.splunk_app_path, self.app)
6365
return self._eventtype_parser
6466

67+
@property
68+
def savedsearch_parser(self):
69+
if not self._savedsearch_parser:
70+
self._savedsearch_parser = SavedSearchParser(self.splunk_app_path,self.app)
71+
return self._savedsearch_parser
72+
6573
def get_props_fields(self):
6674
"""
6775
Parse the props.conf and yield all supported fields
@@ -88,3 +96,12 @@ def get_eventtypes(self):
8896
generator of list of eventtypes
8997
"""
9098
return self.eventtype_parser.get_eventtypes()
99+
100+
def get_savedsearches(self):
101+
"""
102+
Parse the App configuration files & yield searchedservices
103+
104+
Yields:
105+
generator of list of searchedservices
106+
"""
107+
return self.savedsearch_parser.get_savedsearches()

0 commit comments

Comments
 (0)