Before you write your first line of code¶
AUT is a powerful toolset.
Add-on developer experience is the most important for us and we don’t want you to get lost in what is available for you.
Learn from Splunk Add-on for Example¶
Before you start working on your own tests, check splunk-example-ta to get basic understanding of the example TA. Think how you would test it.
Open tests/ucc_modinput_functional
and go through it in proposed below order to see how it is tested. Are your ideas addressed?
tests/ucc_modinput_functional¶
-
README.md
- contains add-on specific information related to the functional tests -
defaults.py
- contains predefined, the tests-specific, constant values -
vendor/
- contains vendor product-specific code-
configuration.py
- to read configuration from environment variables; it can be used later for vendor product-specific means (eg. triggering action that would generate event available for add-on to collect), add-on configuration or within test functions -
client.py
- contains code used to communicate with vendor product
-
-
splunk/
- contains add-on specific code-
client.py
- contains code used to communicate with add-on REST API; relevant code snippets can be found in swagger_client README.md copied from there, pasted to the client file and adopted -
forges.py
- contains functions responsible for creation and deletion of resources and configurations (forges);yield
in each forge, separates setup and teardown -
probes.py
- contains functions validating specific conditions used to make sure that execution of a specific forge indeed resulted in creation of expected resource.
-
-
test_configuration.py
- start simple, eg. from making sure the simplest case liketest_ta_logging
works fine. Keep adding following tests for add-on configuration to make sure you are able to define building blocks that will be used for inputs -
test_inputs.py
- you have proper configuration. There are still two things you need to confirm:-
Make sure vendor product is talkative enough to have always events available for your tests or you need to trigger events generation
-
Input forge should return spl query you will use in input probe as well as in test to get raw events for assertion
-
… also worth considering¶
There are components you may still want to add to your tests:
-
vendor/
-
forges.py
- use if you want to setup and teardown resources in vendor product -
probes.py
-
-
splunk/
configuration.py
- this file is to cover values not related to vendor product, such as proxy accounts
-
test_proxies.py
- to test proxies. Proxy configuration is general for specific add-on, so if defined it will be used for all configuration entries as well as inputs. When constructing this kind of tests you want to isolate them that can be achieved by usingattach
decorator that would group following tasks:-
making sure proxy is defined as required (or disabled if we want to test without proxy configured)
-
relevant configuration creation - especially if validation is used that requires relevant connection to vendor product
-
input creation
-
etc.
-
-
test_validators.py
- to test that add-on will not accept improper values for its configuration. -
etc.
Above is just a proposition that may be relevant for small to medium add-ons.
If you find your add-on more complex, feel free to organize the test structure the way you find the most convenient and efficient.
ucc-test-modinput init¶
Init command is created to save some of your efforts by doing boilerplate actions:
- generates swagger client supporting modules,
- creates unified tests file structure,
- bootstraps basic splunk and vendor clients together with configuration classes,
- initial tests with forges and probes required for them.
This command should be executed once before before any unified tests are created for the project.
-
Before invoking init command, please, make sure:
-
Run
init
to have following directories generated for you:ucc-test-modinput init
-
swagger_client
directory with supporting modules -
tests/ucc_modinput_functional
directory with relevant files and some UCC related tests.
-
Note: You may want to specify openapi.json file location - eg. if it is in Downloads
:
ucc-test-modinput init --openapi-json ~/Downloads/openapi.json
ucc-test-modinput
page for more
-
Set environment variables for your Splunk instance. Eg.:
export MODINPUT_TEST_SPLUNK_HOST=localhost export MODINPUT_TEST_SPLUNK_PORT=8089 export MODINPUT_TEST_SPLUNK_USERNAME=admin export MODINPUT_TEST_SPLUNK_PASSWORD_BASE64=$(ucc-test-modinput base64encode -s 'Chang3d!')
-
Run the tests
pytest tests/ucc_modinput_functional
Note: If your add-on code contains customisations for out of the box components (such as logging or proxy), some tests may fail.