Skip to content

Commit f67468c

Browse files
author
Ryan Faircloth
authored
[ci] Run unit test and integration tests (#2)
1 parent 6d0e0cd commit f67468c

File tree

14 files changed

+126
-36
lines changed

14 files changed

+126
-36
lines changed

.circleci/config.yml

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
executor: << parameters.os >>
2121
steps:
2222
- checkout
23-
- python/load-cache
23+
#- python/load-cache
2424
- run:
2525
name: install deps
2626
command: |
@@ -50,6 +50,75 @@ jobs:
5050
path: test-results
5151
- store_artifacts:
5252
path: htmlcov
53+
54+
test-splunk:
55+
parameters:
56+
os:
57+
type: executor
58+
splunk-version:
59+
type: string
60+
python-version:
61+
type: string
62+
executor: << parameters.os >>
63+
steps:
64+
- checkout
65+
- run: git submodule sync
66+
- run: git submodule update --init
67+
- run:
68+
name: Install Splunk
69+
command: |
70+
pip install git+https://github.com/pixelb/crudini
71+
export SPLUNK_PRODUCT=splunk
72+
export SPLUNK_VERSION=$(crudini --get deps/build/addonfactory_test_matrix_splunk/splunk_matrix.conf "<<parameters.splunk-version>>" VERSION)
73+
export SPLUNK_BUILD=$(crudini --get deps/build/addonfactory_test_matrix_splunk/splunk_matrix.conf "<<parameters.splunk-version>>" BUILD)
74+
export SPLUNK_SLUG=$SPLUNK_VERSION-SPLUNK_BUILD
75+
export SPLUNK_ARCH=x86_64
76+
export SPLUNK_LINUX_FILENAME=splunk-${SPLUNK_VERSION}-${SPLUNK_BUILD}-Linux-${SPLUNK_ARCH}.tgz
77+
export SPLUNK_BUILD_URL=https://download.splunk.com/products/${SPLUNK_PRODUCT}/releases/${SPLUNK_VERSION}/linux/${SPLUNK_LINUX_FILENAME}
78+
echo $SPLUNK_BUILD_URL
79+
export SPLUNK_HOME=/opt/splunk
80+
wget -qO /tmp/splunk.tgz ${SPLUNK_BUILD_URL}
81+
sudo tar -C /opt -zxf /tmp/splunk.tgz
82+
sudo cp -r examples/data/solnlib_demo $SPLUNK_HOME/etc/apps
83+
sudo cp -r solnlib $SPLUNK_HOME/etc/apps/solnlib_demo/bin/
84+
sudo mkdir -p $SPLUNK_HOME/etc/apps/Splunk_TA_test/default/
85+
sudo chown -R $USER:$USER /opt/splunk
86+
ls $SPLUNK_HOME/etc/apps/solnlib_demo/bin/
87+
echo [user_info] >$SPLUNK_HOME/etc/system/local/user-seed.conf
88+
echo USERNAME=Admin >>$SPLUNK_HOME/etc/system/local/user-seed.conf
89+
echo PASSWORD=Chang3d! >>$SPLUNK_HOME/etc/system/local/user-seed.conf
90+
/opt/splunk/bin/splunk start --accept-license
91+
#- python/load-cache
92+
- run:
93+
name: Install deps
94+
command: |
95+
pip install --upgrade pip
96+
pip install --upgrade virtualenv
97+
unset PYENV_ROOT
98+
curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash
99+
export PATH="$HOME/.pyenv/bin:$PATH"
100+
eval "$(pyenv init -)"
101+
pyenv install << parameters.python-version >>
102+
pyenv global << parameters.python-version >>
103+
virtualenv .venv
104+
pip install --upgrade virtualenv
105+
source .venv/bin/activate
106+
pip install -r requirements.txt
107+
pip install -e .
108+
mkdir test-results || true
109+
- python/save-cache
110+
- run:
111+
command: |
112+
source .venv/bin/activate
113+
SPLUNK_HOME=/opt/splunk/ python -m pytest --junitxml=test-results/results.xml -v examples
114+
name: Test
115+
- store_test_results:
116+
path: test-results
117+
- store_artifacts:
118+
path: test-results
119+
- store_artifacts:
120+
path: htmlcov
121+
53122
workflows:
54123
main:
55124
jobs:
@@ -58,3 +127,9 @@ workflows:
58127
parameters:
59128
os: [linux]
60129
python-version: ["2.7.17", "3.7.4"]
130+
- test-splunk:
131+
matrix:
132+
parameters:
133+
os: [linux]
134+
splunk-version: ["7.2", "7.3", "8.0"]
135+
python-version: ["2.7.17", "3.7.4"]

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
.coverage*
44
*.idea
55
*.DS_Store*
6-
build
6+
/build
77
dist
88
docs/_build
99
docs/solnlib
@@ -22,3 +22,6 @@ solnlib.egg-info/
2222
venv/*
2323
*.log
2424
tools/solution_lib_release_env/*
25+
.python-version
26+
.venv
27+
.vscode/settings.json

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "deps/build/addonfactory_test_matrix_splunk"]
2+
path = deps/build/addonfactory_test_matrix_splunk
3+
url = git@github.com:splunk/addonfactory_test_matrix_splunk.git

.python-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/.pytest.expect

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pytest-expect file v1
2+
(3, 7, 7, 'final', 0)

examples/main.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import sys
23
import os
34
import os.path as op
@@ -18,18 +19,18 @@
1819

1920

2021
def setup_environment():
21-
print 'Setup solnlib demo environment...'
22-
print 'Copying %s to %s' % (source_dir, target_dir)
22+
print('Setup solnlib demo environment...')
23+
print('Copying %s to %s' % (source_dir, target_dir))
2324
shutil.copytree(source_dir, target_dir)
2425
shutil.copytree(solnlib_lib_dir,
2526
solnlib_lib_target_dir)
2627
os.system(splunk_bin + ' start')
2728

2829

2930
def teardown_environment():
30-
print 'Teardown solnlib demo environment...'
31+
print('Teardown solnlib demo environment...')
3132
os.system(splunk_bin + ' stop')
32-
print 'Removing %s' % target_dir
33+
print('Removing %s' % target_dir)
3334
if op.exists(target_dir):
3435
shutil.rmtree(target_dir)
3536

@@ -47,31 +48,31 @@ def run_test():
4748
import test_hec_event_writer
4849
import test_time_parser
4950

50-
print 'check splunk environment...'
51+
print('check splunk environment...')
5152
test_splunkenv.test_splunkenv()
52-
print 'check splunk server info...'
53+
print('check splunk server info...')
5354
test_server_info.test_server_info()
54-
print 'test kvstore...'
55+
print('test kvstore...')
5556
test_kvstore.test_kvstore()
56-
print 'test metadata reader...'
57+
print('test metadata reader...')
5758
test_metadata.test_metadata_reader()
58-
print 'test acl manager...'
59+
print('test acl manager...')
5960
test_acl.test_acl_manager()
60-
print 'test credential manager...'
61+
print('test credential manager...')
6162
test_credentials.test_credential_manager()
62-
print 'test conf manager...'
63+
print('test conf manager...')
6364
test_conf_manager.test_conf_manager()
64-
print 'test user access...'
65+
print('test user access...')
6566
test_user_access.test_user_access()
66-
print 'test hec config...'
67+
print('test hec config...')
6768
test_hec_config.test_hec_config()
68-
print 'test hec eventwriter...'
69+
print('test hec eventwriter...')
6970
test_hec_event_writer.test_hec_event_writer()
70-
print 'test time parser...'
71+
print('test time parser...')
7172
test_time_parser.test_time_parser()
7273

7374
if __name__ == '__main__':
7475
teardown_environment()
7576
setup_environment()
7677
run_test()
77-
print 'Run tests success.'
78+
print('Run tests success.')

examples/test_credentials.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from builtins import range
12
import sys
23
import os.path as op
34
import pytest
@@ -19,7 +20,7 @@ def test_credential_manager():
1920
cm.set_password('testuser1', 'password1')
2021
assert cm.get_password('testuser1') == 'password1'
2122

22-
long_password = ''.join(['1111111111' for i in xrange(30)])
23+
long_password = ''.join(['1111111111' for i in range(30)])
2324
cm.set_password('testuser2', long_password)
2425
assert cm.get_password('testuser2') == long_password
2526

examples/test_hec_event_writer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from builtins import range
12
import sys
23
import os.path as op
34

@@ -14,12 +15,12 @@ def test_hec_event_writer():
1415

1516
ew = hew.HECEventWriter("test", session_key)
1617
m1 = {}
17-
for i in xrange(100):
18+
for i in range(100):
1819
m1[i] = "test1 data %s" % i
1920
e1 = ew.create_event(m1, index="main",
2021
host="testing", sourcetype="hec")
2122
m2 = {}
22-
for i in xrange(100):
23+
for i in range(100):
2324
m2[i] = "test2 data %s" % i
2425
e2 = ew.create_event(m2, index="main",
2526
host="testing", sourcetype="hec")

examples/test_kvstore.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from builtins import range
12
import json
23
import os.path as op
34
import sys
@@ -27,7 +28,7 @@ def test_kvstore():
2728
'user': 'string'}
2829

2930
last_ex = None
30-
for i in xrange(3):
31+
for i in range(3):
3132
try:
3233
kvstore.create('sessions', fields=fields)
3334
break

0 commit comments

Comments
 (0)