### Search commands test setup
#### Testing library and dependencies
Testing framework used is [pytest](https://docs.pytest.org/en/stable/) with [PyHamcrest](https://github.com/hamcrest/PyHamcrest) for assertions readability.
For brining up and tearing down in-test-run dockers pytest plugin [pytest-docker](https://pypi.org/project/pytest-docker/) have been used.
`Docker-compose.yml` used for testing resides in `tests` folder.
All set up files used mounted on docker start up for any of set up purposes are placed in `tests/setup_files`.
At the moment this directory have two files:
`tests/setup_files/initializerJson.json` - keeps request expectations for MockServer docker dependencies
`tests/setup_files/virus.conf` - setting file for vt_domain lookup, for now it just holds the url to MockServer in docker environment. This file will placed in `local` directory of `gsirt_searchcommands` splunk app so it will picked up first by splunk sdk due to precedence of reading of configs files which we can levearge for testing purposes.
#### Docker dependencies
All docker dependencies are defined in `docker-compose.yml` from `tests` directory, for now there are two such dependencies:
`splunk/splunk:7.3.5` and `mockserver/mockserver:mockserver-5.11.1`
For any specific settings vide compose file.
MockServer for now mimics only one endpoint from Virus Total domain.
#### Test fixtures
All test fixtures are placed `tests/conftest.py` due to pytest convention. Most of them should be rather self-explanatory and the most important one is `splunk_service` as it waits for Splunk and MockServer dockers to be available.
#### Virtual environment considerations
For the set up of development/test environment [pyenv](https://github.com/pyenv/pyenv) with [virtualenv plugin](https://github.com/pyenv/pyenv-virtualenv) have been used.
Installation steps:
`pyenv install 3.7.7` - both Python 3.6.5 and 3.7.7 have been tested for test set up.
`pyenv virtualenv 3.7.7 yourvirtualenvname-3.7.7`
`pyenv activate yourvirtualenvname-3.7.7`
`pip install -r requirements.dev.txt`
#### Eventgen setup
Eventgen config is `tests/eventgen.conf` - it defines connection parameters to splunk and all data manipulation (vide evenetgen documentation for details). Eventgen is not part of test fixtures as it is strictly command line tool which generates `system.exit(0)` once it finishes - so the best usage is to run it before test run in CI or on your local environment.
Use following command to run: `splunk_eventgen generate eventgen.conf` - run command from same catalogue/directory as configuration file as eventgen seems to have issues with directories and will look for `samples` directory at the level of configuration file.
#### Further considerations
Following considerations should be validated or applied before deciding on final setup of test framework:
<ul>
<li>Run Splunk docker by-side and don't use it in compose for test run due to lengthy time of bringing up for this container. This would also let to generate data with Eventgen. </li>
<li>Script eventgen data load so it will be automated for local development and CI</li>
<li>Tweak tests output for readability</li>
<li>Keep MockServer as part of in-test docker compose</li>
</ul>