Skip to content

Commit fea51e9

Browse files
author
Frederick Ross
committed
Made skipping without sdk-app-collection actually work. (Didn't before…)
1 parent 942b48a commit fea51e9

File tree

5 files changed

+51
-21
lines changed

5 files changed

+51
-21
lines changed

tests/test_index.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ def test_submit_via_attached_socket(self):
111111
sock.send('Hello world!\r\n')
112112
self.assertEventuallyTrue(lambda: self.totalEventCount() == eventCount+1, timeout=60)
113113

114-
@unittest.skipUnless(testlib.has_app_collection, "Test requires sdk-app-collection.")
115114
def test_upload(self):
115+
if not self.app_collection_installed():
116+
print "Test requires sdk-app-collection. Skipping."
117+
return
116118
self.install_app_from_collection("file_to_upload")
117119

118120
eventCount = int(self.index['totalEventCount'])

tests/test_input.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,10 @@ def test_inputs_list_on_one_kind_with_search(self):
147147
found = [x.name for x in self.service.inputs.list('monitor', search=search)]
148148
self.assertEqual(expected, found)
149149

150-
@unittest.skipUnless(testlib.has_app_collection, "Test requires sdk-app-collection.")
151150
def test_oneshot(self):
151+
if not self.app_collection_installed():
152+
print "Test requires sdk-app-collection. Skipping."
153+
return
152154
self.install_app_from_collection('file_to_upload')
153155

154156
index_name = testlib.tmpname()
@@ -205,10 +207,13 @@ def test_list(self):
205207
for input in input_list:
206208
self.assertTrue(input.name is not None)
207209

208-
@unittest.skipUnless(testlib.has_app_collection, "Test requires sdk-app-collection.")
209210
def test_lists_modular_inputs(self):
210211
if self.service.splunk_version[0] < 5:
211-
return # Modular inputs don't exist prior to 5.0
212+
print "Modular inputs don't exist prior to Splunk 5.0. Skipping."
213+
return
214+
elif not self.app_collection_installed():
215+
print "Test requires sdk-app-collection. Skipping."
216+
return
212217
else:
213218
# Install modular inputs to list, and restart
214219
# so they'll show up.

tests/test_job.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,33 +114,48 @@ def test_read_jobs(self):
114114
job.refresh()
115115
self.check_job(job)
116116

117-
@unittest.skipUnless(testlib.has_app_collection, "Test requires sdk-app-collection.")
118117
class TestJobWithDelayedDone(testlib.SDKTestCase):
119118
def setUp(self):
120119
super(TestJobWithDelayedDone, self).setUp()
120+
self.job = None
121+
122+
def tearDown(self):
123+
super(TestJobWithDelayedDone, self).tearDown()
124+
if self.job is not None:
125+
self.job.cancel()
126+
self.assertEventuallyTrue(lambda: self.job.sid not in self.service.jobs)
127+
128+
def test_enable_preview(self):
129+
if not self.app_collection_installed():
130+
print "Test requires sdk-app-collection. Skipping."
131+
return
121132
self.install_app_from_collection("sleep_command")
122-
self.query = "search index=_internal | sleep done=100"
133+
self.query = "search index=_internal | sleep 100"
123134
self.job = self.service.jobs.create(
124135
query=self.query,
125136
earliest_time="-1m",
126137
priority=5,
127138
latest_time="now")
128-
129-
def tearDown(self):
130-
super(TestJobWithDelayedDone, self).tearDown()
131-
self.job.cancel()
132-
self.assertEventuallyTrue(lambda: self.job.sid not in self.service.jobs)
133-
134-
def test_enable_preview(self):
135139
self.assertEqual(self.job['isPreviewEnabled'], '0')
136140
self.job.enable_preview()
137141
def is_preview():
142+
self.job.refresh()
138143
if self.job.is_done():
139144
self.fail('Job finished before preview enabled.')
140145
return self.job['isPreviewEnabled'] == '1'
141146
self.assertEventuallyTrue(is_preview)
142147

143148
def test_setpriority(self):
149+
if not self.app_collection_installed():
150+
print "Test requires sdk-app-collection. Skipping."
151+
return
152+
self.install_app_from_collection("sleep_command")
153+
self.query = "search index=_internal | sleep 100"
154+
self.job = self.service.jobs.create(
155+
query=self.query,
156+
earliest_time="-1m",
157+
priority=5,
158+
latest_time="now")
144159
# Note that you can only *decrease* the priority (i.e., 5 decreased to 3)
145160
# of a job unless Splunk is running as root. This is because Splunk jobs
146161
# are tied up with operating system processes and their priorities.
@@ -232,7 +247,7 @@ def test_touch(self):
232247
# This cannot be tested very fast. touch will reset the ttl to the original value for the job,
233248
# so first we have to wait just long enough for the ttl to tick down. Its granularity is 1s,
234249
# so we'll wait 1.1s before we start.
235-
import time; time.sleep(1.1)
250+
import time; time.sleep(2)
236251
old_ttl = int(self.job['ttl'])
237252
self.job.touch()
238253
self.job.refresh()

tests/test_modular_input_kinds.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@
2121
import unittest2 as unittest
2222
import splunklib.client as client
2323

24-
@unittest.skipUnless(testlib.has_app_collection, "Test requires sdk-app-collection.")
2524
class ModularInputKindTestCase(testlib.SDKTestCase):
2625
def setUp(self):
2726
super(ModularInputKindTestCase, self).setUp()
28-
self.install_app_from_collection("modular-inputs")
2927
self.uncheckedRestartSplunk()
3028

3129
def test_list_arguments(self):
30+
if not self.app_collection_installed():
31+
print "Test requires sdk-app-collection. Skipping."
32+
return
33+
self.install_app_from_collection("modular-inputs")
34+
3235
if self.service.splunk_version[0] < 5:
3336
# Not implemented before 5.0
3437
return
@@ -43,6 +46,11 @@ def test_list_arguments(self):
4346
self.assertEqual(expected_args, found_args)
4447

4548
def test_update_raises_exception(self):
49+
if not self.app_collection_installed():
50+
print "Test requires sdk-app-collection. Skipping."
51+
return
52+
self.install_app_from_collection("modular-inputs")
53+
4654
if self.service.splunk_version[0] < 5:
4755
# Not implemented before 5.0
4856
return
@@ -59,6 +67,11 @@ def check_modular_input_kind(self, m):
5967
self.assertEqual('simple', m['streaming_mode'])
6068

6169
def test_list_modular_inputs(self):
70+
if not self.app_collection_installed():
71+
print "Test requires sdk-app-collection. Skipping."
72+
return
73+
self.install_app_from_collection("modular-inputs")
74+
6275
if self.service.splunk_version[0] < 5:
6376
# Not implemented before 5.0
6477
return

tests/testlib.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ class NoRestartRequiredError(Exception):
5151
class WaitTimedOutError(Exception):
5252
pass
5353

54-
has_app_collection = False
55-
5654
def to_bool(x):
5755
if x == '1':
5856
return True
@@ -233,9 +231,6 @@ def setUpClass(cls):
233231
if service.restart_required:
234232
service.restart(timeout=120)
235233

236-
global has_app_collection
237-
has_app_collection = 'sdk-app-collection' in service.apps
238-
239234
def setUp(self):
240235
unittest.TestCase.setUp(self)
241236
self.service = client.connect(**self.opts.kwargs)

0 commit comments

Comments
 (0)