Merge "Improving Unit Test coverage of k8s_manifest"
This commit is contained in:
commit
fe745434a8
|
@ -50,7 +50,8 @@ def parse(manifest_str):
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
else:
|
else:
|
||||||
if manifest is None:
|
if manifest is None:
|
||||||
manifest = {}
|
msg = _("'manifest' can't be empty")
|
||||||
|
raise ValueError(msg)
|
||||||
|
|
||||||
if not isinstance(manifest, dict):
|
if not isinstance(manifest, dict):
|
||||||
raise ValueError(_('The manifest is not a JSON object '
|
raise ValueError(_('The manifest is not a JSON object '
|
||||||
|
|
|
@ -19,13 +19,15 @@ from magnum.tests import base
|
||||||
class K8sManifestTestCase(base.TestCase):
|
class K8sManifestTestCase(base.TestCase):
|
||||||
|
|
||||||
def test_parse_with_json(self):
|
def test_parse_with_json(self):
|
||||||
|
port = 6379
|
||||||
|
containerPort = 6380
|
||||||
json_str = '''
|
json_str = '''
|
||||||
{
|
{
|
||||||
"id": "redis-master",
|
"id": "redis-master",
|
||||||
"kind": "Service",
|
"kind": "Service",
|
||||||
"apiVersion": "v1beta1",
|
"apiVersion": "v1beta1",
|
||||||
"port": 6379,
|
"port": %d,
|
||||||
"containerPort": 6379,
|
"containerPort": %d,
|
||||||
"selector": {
|
"selector": {
|
||||||
"name": "redis-master"
|
"name": "redis-master"
|
||||||
},
|
},
|
||||||
|
@ -33,27 +35,48 @@ class K8sManifestTestCase(base.TestCase):
|
||||||
"name": "redis-master"
|
"name": "redis-master"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'''
|
''' % (port, containerPort)
|
||||||
|
|
||||||
manifest = k8s_manifest.parse(json_str)
|
manifest = k8s_manifest.parse(json_str)
|
||||||
self.assertIsInstance(manifest, dict)
|
self.assertIsInstance(manifest, dict)
|
||||||
|
self.assertEqual(port, manifest['port'])
|
||||||
|
self.assertEqual(containerPort, manifest['containerPort'])
|
||||||
|
|
||||||
def test_parse_with_yaml(self):
|
def test_parse_with_yaml(self):
|
||||||
|
port = 6389
|
||||||
|
containerPort = 6380
|
||||||
yaml_str = '''
|
yaml_str = '''
|
||||||
id: redis-master
|
id: redis-master
|
||||||
kind: Service
|
kind: Service
|
||||||
port: 6379
|
port: %d
|
||||||
containerPort: 6379
|
containerPort: %d
|
||||||
selector:
|
selector:
|
||||||
name: redis-master
|
name: redis-master
|
||||||
labels:
|
labels:
|
||||||
name: redis-master
|
name: redis-master
|
||||||
'''
|
''' % (port, containerPort)
|
||||||
|
|
||||||
manifest = k8s_manifest.parse(yaml_str)
|
manifest = k8s_manifest.parse(yaml_str)
|
||||||
self.assertIsInstance(manifest, dict)
|
self.assertIsInstance(manifest, dict)
|
||||||
|
self.assertEqual(port, manifest['port'])
|
||||||
|
self.assertEqual(containerPort, manifest['containerPort'])
|
||||||
|
|
||||||
def test_parse_invalid_value(self):
|
def test_parse_invalid_value(self):
|
||||||
invalid_str = 'aoa89**'
|
invalid_str = 'aoa89**'
|
||||||
|
|
||||||
self.assertRaises(ValueError, k8s_manifest.parse, invalid_str)
|
self.assertRaises(ValueError, k8s_manifest.parse, invalid_str)
|
||||||
|
|
||||||
|
def test_parse_empty_value(self):
|
||||||
|
empty_str = ''
|
||||||
|
|
||||||
|
self.assertRaises(ValueError, k8s_manifest.parse, empty_str)
|
||||||
|
|
||||||
|
def test_parse_empty_yaml_response(self):
|
||||||
|
blank_str = ' '
|
||||||
|
|
||||||
|
self.assertRaises(ValueError, k8s_manifest.parse, blank_str)
|
||||||
|
|
||||||
|
def test_parse_yaml_error(self):
|
||||||
|
invalid_str = "}invalid: y'm'l3!"
|
||||||
|
|
||||||
|
self.assertRaises(ValueError, k8s_manifest.parse, invalid_str)
|
||||||
|
|
Loading…
Reference in New Issue