예제 #1
0
 def test_check_http_unsupported_method(self):
     ServiceCheck.consul_version = (0, 8, 4)
     params = self.params_http
     del params['body']
     check = ServiceCheck.http(self.dummyservice, params)
     # method isn't supported, check should be None
     self.assertIsNone(check)
예제 #2
0
 def test_check_script_consul_1(self):
     ServiceCheck.consul_version = (0, 9, 6)
     params = self.params_script
     with pytest.deprecated_call():
         check = ServiceCheck.script(self.dummyservice, params)
     self.assertEqual(check['script'], 'command arg1 arg2')
     self.assertEqual(check['interval'], '5s')
     self.assertEqual(len(check), 2)
예제 #3
0
 def test_check_tcp(self):
     params = self.params_tcp
     check = ServiceCheck.tcp(self.dummyservice, params)
     self.assertEqual(check['tcp'], '6.6.6.6:666')
     self.assertEqual(check['interval'], '17s')
     self.assertEqual(check['timeout'], '3s')
     self.assertEqual(check['DeregisterCriticalServiceAfter'], '666s')
     self.assertEqual(len(check), 4)
예제 #4
0
 def test_check_docker(self):
     params = self.params_docker
     check = ServiceCheck.docker(self.dummyservice, params)
     print(check)
     # {'docker_container_id': 'deadbeef', 'shell': '/bin/sh', 'interval': '5s', 'args': ['command', 'arg1', 'arg2']}
     self.assertEqual(check['args'], ['command', 'arg1', 'arg2'])
     self.assertEqual(check['docker_container_id'], 'deadbeef')
     self.assertEqual(check['shell'], '/bin/sh')
     self.assertEqual(check['interval'], '5s')
     self.assertEqual(len(check), 4)
예제 #5
0
 def test_check_https(self):
     params = self.params_https
     check = ServiceCheck.https(self.dummyservice, params)
     self.assertEqual(check['http'], 'https://6.6.6.6:666/path')
     self.assertEqual(check['interval'], '17s')
     self.assertEqual(check['timeout'], '3s')
     self.assertEqual(check['header'], {'x-foo': ['bar', 'baz']})
     self.assertEqual(check['Method'], 'HEAD')
     self.assertEqual(check['Body'], params['body'])
     self.assertEqual(len(check), 6)
예제 #6
0
 def test_check_docker_consul_1(self):
     ServiceCheck.consul_version = (0, 9, 6)
     params = self.params_docker
     check = ServiceCheck.docker(self.dummyservice, params)
     print(check)
     # {'docker_container_id': 'deadbeef', 'shell': '/bin/sh', 'interval': '5s', 'args': ['command', 'arg1', 'arg2']}
     self.assertEqual(check['script'], 'command arg1 arg2')
     self.assertEqual(check['docker_container_id'], 'deadbeef')
     self.assertEqual(check['shell'], '/bin/sh')
     self.assertEqual(check['interval'], '5s')
     self.assertEqual(len(check), 4)
예제 #7
0
 def test_check_http(self):
     params = self.params_http
     check = ServiceCheck.http(self.dummyservice, params)
     self.assertEqual(check['http'], 'http://6.6.6.6:666/path')
     self.assertEqual(check['interval'], '17s')
     self.assertEqual(check['timeout'], '3s')
     self.assertEqual(check['header'], {'x-foo': ['bar', 'baz']})
     self.assertEqual(check['Method'], 'HEAD')
     self.assertEqual(check['Body'], params['body'])
     self.assertEqual(check['DeregisterCriticalServiceAfter'], '666s')
     self.assertEqual(check['Status'], 'passing')
     self.assertEqual(len(check), 8)
예제 #8
0
 def test_no_default(self):
     value = ServiceCheck._value(self.params, 'unknownkey')
     self.assertIsNone(value)
예제 #9
0
 def test_check_script_empty(self):
     params = self.params_script
     params['script'] = ''
     check = ServiceCheck.script(self.dummyservice, params)
     self.assertIsNone(check)
예제 #10
0
 def test_check_script_replace(self):
     params = self.params_script
     params['script'] = 'command $SERVICE_IP:$SERVICE_PORT'
     check = ServiceCheck.script(self.dummyservice, params)
     self.assertEqual(check['args'], ['command', '6.6.6.6:666'])
예제 #11
0
 def test_check_script(self):
     params = self.params_script
     check = ServiceCheck.script(self.dummyservice, params)
     self.assertEqual(check['args'], ['command', 'arg1', 'arg2'])
     self.assertEqual(check['interval'], '5s')
     self.assertEqual(len(check), 2)
예제 #12
0
 def test_check_http_no_method(self):
     params = self.params_http
     del params['http_method']
     check = ServiceCheck.http(self.dummyservice, params)
     self.assertNotIn('Method', check)
예제 #13
0
 def test_json_value_empty(self):
     self.params['key'] = ''
     value = ServiceCheck._json_value(self.params, 'key')
     self.assertIsNone(value)
예제 #14
0
 def test_check_http_invalid_header(self):
     params = self.params_http
     params['header'] = 'invalid_json'
     check = ServiceCheck.http(self.dummyservice, params)
     self.assertNotIn('header', check)
예제 #15
0
 def test_check_docker_empty(self):
     params = self.params_docker
     params['docker'] = ''
     check = ServiceCheck.docker(self.dummyservice, params)
     self.assertIsNone(check)
예제 #16
0
 def test_check_https_skip_verify_false(self):
     params = self.params_https
     params['tls_skip_verify'] = 'false'
     check = ServiceCheck.https(self.dummyservice, params)
     self.assertNotIn('TLSSkipVerify', check)
예제 #17
0
 def test_check_https_skip_verify_true(self):
     params = self.params_https
     params['tls_skip_verify'] = 'TrUe'
     check = ServiceCheck.https(self.dummyservice, params)
     self.assertIn('TLSSkipVerify', check)
     self.assertTrue(check['TLSSkipVerify'])
예제 #18
0
 def test_value(self):
     value = ServiceCheck._value(self.params, 'key')
     self.assertEqual(value, 'val')
예제 #19
0
 def test_check_http_no_body(self):
     params = self.params_http
     del params['body']
     check = ServiceCheck.http(self.dummyservice, params)
     self.assertNotIn('Body', check)
예제 #20
0
 def test_json_value_ok(self):
     self.params['key'] = '{"k": "v"}'
     value = ServiceCheck._json_value(self.params, 'key')
     self.assertIn('k', value)
     self.assertEqual(value['k'], 'v')
예제 #21
0
 def test_check_http_unsupported_body(self):
     ServiceCheck.consul_version = (1, 0, 0)
     params = self.params_http
     check = ServiceCheck.http(self.dummyservice, params)
     # body isn't supported, check should be None
     self.assertIsNone(check)
예제 #22
0
 def test_bool_value_true(self):
     self.params['key'] = 'true'
     value = ServiceCheck._bool_value(self.params, 'key')
     self.assertTrue(value)
예제 #23
0
 def test_check_tcp_false(self):
     params = self.params_tcp
     params['tcp'] = 'false'
     check = ServiceCheck.tcp(self.dummyservice, params)
     self.assertIsNone(check)
예제 #24
0
 def test_bool_value_false(self):
     self.params['key'] = 'untrue'
     value = ServiceCheck._bool_value(self.params, 'key')
     self.assertFalse(value)
예제 #25
0
 def test_value_default(self):
     del self.params['key']
     value = ServiceCheck._value(self.params, 'key')
     self.assertEqual(value, 'defval')
예제 #26
0
 def test_json_value_not_ok(self):
     self.params['key'] = '{"k": "v",}'
     value = ServiceCheck._json_value(self.params, 'key')
     self.assertIsNone(value)
예제 #27
0
 def test_check_ttl(self):
     params = self.params_ttl
     check = ServiceCheck.ttl(self.dummyservice, params)
     self.assertEqual(check['ttl'], '17s')
     self.assertEqual(len(check), 1)
예제 #28
0
 def test_check_ttl_empty(self):
     params = self.params_ttl
     params['ttl'] = ''
     check = ServiceCheck.ttl(self.dummyservice, params)
     self.assertIsNone(check)
예제 #29
0
 def test_check_http_no_path(self):
     params = self.params_http
     params['http'] = ''
     check = ServiceCheck.http(self.dummyservice, params)
     self.assertIsNone(check)