A Dynamic test tool for Splunk Apps and Add-ons
The detailed documentation for pytest-splunk-addon can be found here : https://pytest-splunk-addon.readthedocs.io/
- Generate tests for Splunk Knowledge objects in your Splunk Technology Add-ons
- Validate your add-ons using Splunk + Docker and this test tool
- Docker or an external single instance Splunk deployment
You can install "pytest-splunk-addon" via pip from PyPI:
$ pip install pytest-splunk-addon
Note: Must install docker desktop.
$ git clone --recurse-submodules -j8 git@github.com:splunk/pytest-splunk-addon.git
$ cd pytest-splunk-addon
$ poetry install
$ ... (change something)
# run unit tests
$ poetry run pytest tests/unit
# run some of the docker-based tests to verify end-to-end behaviour, example:
$ poetry run pytest -v --splunk-version=8.2 -m docker tests/test_splunk_addon.py::test_splunk_app_requirements_modinput
Installation for external Splunk
pip install pytest-splunk-addon
Installation with built in docker orchestration
pip install pytest-splunk-addon[docker]
Basic project structure
The tool assumes the Splunk Add-on is located in a folder "package" in the project root
Triggering the tool:
Create a test file in the tests folder
from pytest_splunk_addon.standard_lib.addon_basic import Basic
class Test_App(Basic):
def empty_method():
pass
Create a Dockerfile-splunk file
ARG SPLUNK_VERSION=latest
FROM splunk/splunk:$SPLUNK_VERSION
ARG SPLUNK_APP=TA_UNKNOWN
ARG SPLUNK_APP_PACKAGE=package
COPY deps/apps /opt/splunk/etc/apps/
COPY $SPLUNK_APP_PACKAGE /opt/splunk/etc/apps/$SPLUNK_APP
Create a docker-compose.yml update the value of SPLUNK_APP
version: "3.7"
services:
splunk:
build:
context: .
dockerfile: Dockerfile-splunk
args:
- SPLUNK_APP=xxxxxxx
ports:
- "8000"
- "8089"
environment:
- SPLUNK_PASSWORD=Changed@11
- SPLUNK_START_ARGS=--accept-license
Run pytest with the add-on and SA-eventgen installed and enabled in an external Splunk deployment
Run pytest with the add-on and SA-eventgen installed and enabled in docker
For full usage instructions, please visit the pytest-splunk-addon documentation pages over at readthedocs.
Contributions are very welcome. Tests can be run with pytest, please ensure the coverage at least stays the same before you submit a pull request.
Distributed under the terms of the Apache Software License 2.0 license, "pytest-splunk-addon" is free and open source software
If you encounter any problems, please file an issue along with a detailed description.