Commit 4d2b69e4 authored by Tristan Cavelier's avatar Tristan Cavelier Committed by Alain Takoudjou

check_apachedex_result: rephrase messages

test_check_apachedex_result: also extract promise messages from test methods
parent 84a8dbe5
...@@ -36,9 +36,9 @@ def checkApachedexResult(apachedex_path, apachedex_report_status_file, desired_t ...@@ -36,9 +36,9 @@ def checkApachedexResult(apachedex_path, apachedex_report_status_file, desired_t
if m: if m:
apx_result=int(m[0]) apx_result=int(m[0])
if apx_result > desired_threshold: if apx_result > desired_threshold:
return 0, "Thanks for keeping it all clean, result is %s" % apx_result return 0, "OK - Score: {}%".format(apx_result)
else: else:
return 1, "Threshold is lower than expected: Expected was %s and current result is %s" % (desired_threshold, apx_result) return 1, "Score too low: {}% - Threshold: {}%".format(apx_result, desired_threshold)
message = "No result found in the apdex file or the file is corrupted" message = "No result found in the apdex file or the file is corrupted"
break break
......
...@@ -35,6 +35,11 @@ import shutil ...@@ -35,6 +35,11 @@ import shutil
from slapos.test.promise import data from slapos.test.promise import data
from slapos.promise.check_apachedex_result import checkApachedexResult from slapos.promise.check_apachedex_result import checkApachedexResult
apdex_not_found_message = "No result found in the apdex file or the file is corrupted"
low_score_message_formater = "Score too low: {}% - Threshold: {}%"
ok_message_formater = "OK - Score: {}%"
skip_message = "Instance has been just deployed. Skipping check.."
class TestCheckApacheDigestResult(unittest.TestCase): class TestCheckApacheDigestResult(unittest.TestCase):
def _create_file(self, date, with_content): def _create_file(self, date, with_content):
...@@ -71,26 +76,27 @@ class TestCheckApacheDigestResult(unittest.TestCase): ...@@ -71,26 +76,27 @@ class TestCheckApacheDigestResult(unittest.TestCase):
def test_threshold_is_greater(self): def test_threshold_is_greater(self):
status, message = checkApachedexResult(self.base_dir, self.status_file, 60) status, message = checkApachedexResult(self.base_dir, self.status_file, 60)
self.assertEquals("Thanks for keeping it all clean, result is 80", message) self.assertEquals(ok_message_formater.format(80), message)
self.assertEquals(0, status) self.assertEquals(0, status)
def test_no_today_file_and_empty_yesterday_file(self): def test_no_today_file_and_empty_yesterday_file(self):
self._remove_file(self.today) self._remove_file(self.today)
status, message = checkApachedexResult(self.base_dir, self.status_file, 60) status, message = checkApachedexResult(self.base_dir, self.status_file, 60)
self.assertEquals("No result found in the apdex file or the file is corrupted", message) self.assertEquals(apdex_not_found_message, message)
self.assertEquals(1, status) self.assertEquals(1, status)
self._create_file(self.today, True) self._create_file(self.today, True)
def test_threshold_is_lower(self): def test_threshold_is_lower(self):
threshold = 90.0
status, message = checkApachedexResult(self.base_dir, self.status_file, threshold) status, message = checkApachedexResult(self.base_dir, self.status_file, threshold)
self.assertEquals("Threshold is lower than expected: Expected was 90.0 and current result is 80", message) self.assertEquals(low_score_message_formater.format(80, threshold), message)
self.assertEquals(1, status) self.assertEquals(1, status)
def test_no_today_file_but_yesterday_file(self): def test_no_today_file_but_yesterday_file(self):
self._remove_file(self.today) self._remove_file(self.today)
self._create_file(self.yesterday, True) self._create_file(self.yesterday, True)
status, message = checkApachedexResult(self.base_dir, self.status_file, 60) status, message = checkApachedexResult(self.base_dir, self.status_file, 60)
self.assertEquals("Thanks for keeping it all clean, result is 80", message) self.assertEquals(ok_message_formater.format(80), message)
self.assertEquals(0, status) self.assertEquals(0, status)
self._create_file(self.today, True) self._create_file(self.today, True)
self._remove_file(self.yesterday) self._remove_file(self.yesterday)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment