Skip to content

Commit 1ec510f

Browse files
committed
fix: test threshold simplication
1 parent a291606 commit 1ec510f

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

test/nagios.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ def test_eval(self):
6868

6969
def test_cache(self):
7070
"""Test the caching mechanism in the reporter."""
71-
length = random.randint(1, 30)
72-
7371
message = "huppeldepup a test string"
7472

7573
threshold = None
@@ -107,7 +105,7 @@ def test_cache(self):
107105
def test_threshold(self, message="Hello"):
108106
"""Test the threshold borking mechanism in the reporter."""
109107
message = message.rstrip()
110-
threshold = 1
108+
threshold = 2
111109
if message == '':
112110
return
113111

@@ -123,8 +121,8 @@ def test_threshold(self, message="Hello"):
123121
reporter.cache(nagios_exit, message)
124122

125123
raised_exception = None
124+
reporter_test = NagiosReporter('test_cache', filename, threshold, self.nagios_user)
126125
try:
127-
reporter_test = NagiosReporter('test_cache', filename, threshold, self.nagios_user)
128126
reporter_test.report_and_exit()
129127
except SystemExit as err:
130128
raised_exception = err
@@ -133,19 +131,10 @@ def test_threshold(self, message="Hello"):
133131
# restore stdout
134132
buff.close()
135133

136-
sys.stdout = old_stdout
137-
138-
reporter = NagiosReporter('test_cache', filename, threshold, self.nagios_user)
139-
reporter.cache(nagios_exit, message)
140134
time.sleep(threshold + 1)
141-
# redirect stdout
142-
old_stdout = sys.stdout
143135
buff = StringIO()
144-
sys.stdout = buff
145-
146136
raised_exception = None
147137
try:
148-
reporter_test = NagiosReporter('test_cache', filename, threshold, self.nagios_user)
149138
reporter_test.report_and_exit()
150139
except SystemExit as err:
151140
raised_exception = err
@@ -156,8 +145,7 @@ def test_threshold(self, message="Hello"):
156145
sys.stdout = old_stdout
157146
self.assertEqual(raised_exception.code, NAGIOS_EXIT_UNKNOWN[0],
158147
"Too old caches lead to unknown status")
159-
self.assertTrue(line.startswith("%s test_cache gzipped JSON file too old (timestamp =" %
160-
(NAGIOS_EXIT_UNKNOWN[1])))
148+
self.assertTrue(line.startswith("%s test_cache nagios exit info expired" % (NAGIOS_EXIT_UNKNOWN[1])))
161149

162150
shutil.rmtree(filename)
163151

0 commit comments

Comments
 (0)