[PATCH 2/2] increasing test coverage on agent

Dan Radez dradez at redhat.com
Fri Dec 9 15:07:11 UTC 2011


---
 agent/test_audrey_agent.py |   53 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/agent/test_audrey_agent.py b/agent/test_audrey_agent.py
index d87c05f..e9c65bb 100644
--- a/agent/test_audrey_agent.py
+++ b/agent/test_audrey_agent.py
@@ -84,12 +84,18 @@ class HttpUnitTest(object):
     ok_response = HttpUnitTestResponse(200)
     not_found_response = HttpUnitTestResponse(404)
 
+    def __init__(self, always_404=False):
+        self.always_404 = always_404
+
     def request(self, url, method='GET', body=None, headers=None):
         '''
         Handle request when not running live but in test environment.
         '''
         body = ''
-        response = HttpUnitTest.ok_response
+        if self.always_404 and not url.endswith('/user-data'):
+            return HttpUnitTest.not_found_response, body
+        else:
+            response = HttpUnitTest.ok_response
         if method == 'GET':
             if url.find('/configs/') > -1:
                 body = '|service|s1|parameters|param1&%s|param2&%s|' % \
@@ -113,7 +119,6 @@ class HttpUnitTest(object):
                 body = base64.b64encode(DUMMY_USER_DATA)
                 response = HttpUnitTest.not_found_response
             else:
-                print url
                 response = HttpUnitTest.not_found_response
         #elif method == 'POST' and url.find('/params/') > -1:
         #    body = ''
@@ -134,6 +139,10 @@ class TestAudreyStarupRunCmds(unittest.TestCase):
         self.assertEqual("'test'\n",
             _run_pipe_cmd(["echo", "'test'"], ["grep", "test"])['out'])
 
+    def test_fail_run_cmd(self):
+        self.assertEqual("[Errno 2] No such file or directory",
+            _run_cmd(["notreal"])['err'])
+
     def test_cmd2_fail_run_pipe_cmd(self):
         self.assertEqual("[Errno 2] No such file or directory",
             _run_pipe_cmd(["echo", "'test'"], ["notreal"])['err'])
@@ -322,6 +331,24 @@ class TestAudreyStartupRequiredConfig(unittest.TestCase):
             print 'parse_require_config returned: ' + \
                 str(parse_require_config(src))
 
+    def test_failure_service_tag_not_found(self):
+        '''
+        Failure Case:
+        - |service| not in src to parse_require_config()
+        '''
+        src = '|notservice|blah|'
+        with self.assertRaises(ASError):
+            parse_require_config(src)
+
+    def test_failure_no_amp_delim(self):
+        '''
+        Failure Case:
+        - no delim in param token
+        '''
+        src = '|service|blah|parameters|blah|'
+        with self.assertRaises(ASError):
+            parse_require_config(src)
+
 class TestAudreyStartupDiscovery(unittest.TestCase):
     def setUp(self):
         '''
@@ -426,6 +453,18 @@ class TestAudreyStartupProvidesParameters(unittest.TestCase):
         for param in expected_params_list:
             self.assertTrue('%7C' + str(param) in provides)
 
+    def test_success_empty_params(self):
+        '''
+        Success case:
+        - Exercise parse_provides_params() and generate_provides()
+          with valid demlims but empty input
+        '''
+        src = '||'
+        params_list = parse_provides_params(src)
+        provides = generate_provides(src)
+        self.assertEqual(params_list, [''])
+        self.assertEqual(provides, 'audrey_data=%7C%26%7C')
+
     def test_success_no_params(self):
         '''
         Success case:
@@ -679,6 +718,16 @@ class TestAudreyScript(unittest.TestCase):
         '''
         self.assertRaises(ASError, audrey_script_main)
 
+    def test_fail_audrey_script_main_404(self):
+        '''
+        Perform what the audrey script will do.
+        '''
+        cloud_info_file = 'cloud_info'
+        sys.argv.extend(['-p'])
+        _write_info_file(cloud_info_file, 'EC2')
+        self.assertRaises(ASError, audrey_script_main, HttpUnitTest(True))
+        os.remove(cloud_info_file)
+
     def test_empty_gen_env(self):
         self.assertRaises(ASError, gen_env, '', '')
 
-- 
1.7.7.3




More information about the aeolus-devel mailing list