Skip to content

Commit

Permalink
Ability to run e2e tests multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
dims committed Jan 25, 2017
1 parent 13ac533 commit cf5d796
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions kubernetes/e2e_test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def test_pod_apis(self):
api = core_v1_api.CoreV1Api(client)

name = 'test-' + str(uuid.uuid4())

pod_manifest = {'apiVersion': 'v1',
'kind': 'Pod',
'metadata': {'color': 'blue', 'name': name},
Expand Down Expand Up @@ -84,38 +83,39 @@ def test_service_apis(self):
client = api_client.ApiClient('http://127.0.0.1:8080/')
api = core_v1_api.CoreV1Api(client)

name = 'frontend-' + str(uuid.uuid4())
service_manifest = {'apiVersion': 'v1',
'kind': 'Service',
'metadata': {'labels': {'name': 'frontend'},
'name': 'frontend',
'metadata': {'labels': {'name': name},
'name': name,
'resourceversion': 'v1'},
'spec': {'ports': [{'name': 'port',
'port': 80,
'protocol': 'TCP',
'targetPort': 80}],
'selector': {'name': 'frontend'}}}
'selector': {'name': name}}}

resp = api.create_namespaced_service(body=service_manifest,
namespace='default')
self.assertEqual('frontend', resp.metadata.name)
self.assertEqual(name, resp.metadata.name)
self.assertTrue(resp.status)

resp = api.read_namespaced_service(name='frontend',
resp = api.read_namespaced_service(name=name,
namespace='default')
self.assertEqual('frontend', resp.metadata.name)
self.assertEqual(name, resp.metadata.name)
self.assertTrue(resp.status)

service_manifest['spec']['ports'] = [{'name': 'new',
'port': 8080,
'protocol': 'TCP',
'targetPort': 8080}]
resp = api.patch_namespaced_service(body=service_manifest,
name='frontend',
name=name,
namespace='default')
self.assertEqual(2, len(resp.spec.ports))
self.assertTrue(resp.status)

resp = api.delete_namespaced_service(name='frontend',
resp = api.delete_namespaced_service(name=name,
namespace='default')

@unittest.skipUnless(
Expand All @@ -124,15 +124,16 @@ def test_replication_controller_apis(self):
client = api_client.ApiClient('http://127.0.0.1:8080/')
api = core_v1_api.CoreV1Api(client)

name = 'frontend-' + str(uuid.uuid4())
rc_manifest = {
'apiVersion': 'v1',
'kind': 'ReplicationController',
'metadata': {'labels': {'name': 'frontend'},
'name': 'frontend'},
'metadata': {'labels': {'name': name},
'name': name},
'spec': {'replicas': 2,
'selector': {'name': 'frontend'},
'selector': {'name': name},
'template': {'metadata': {
'labels': {'name': 'frontend'}},
'labels': {'name': name}},
'spec': {'containers': [{
'image': 'nginx',
'name': 'nginx',
Expand All @@ -141,16 +142,16 @@ def test_replication_controller_apis(self):

resp = api.create_namespaced_replication_controller(
body=rc_manifest, namespace='default')
self.assertEqual('frontend', resp.metadata.name)
self.assertEqual(name, resp.metadata.name)
self.assertEqual(2, resp.spec.replicas)

resp = api.read_namespaced_replication_controller(
name='frontend', namespace='default')
self.assertEqual('frontend', resp.metadata.name)
name=name, namespace='default')
self.assertEqual(name, resp.metadata.name)
self.assertEqual(2, resp.spec.replicas)

resp = api.delete_namespaced_replication_controller(
name='frontend', body={}, namespace='default')
name=name, body={}, namespace='default')


@unittest.skipUnless(
Expand All @@ -159,11 +160,12 @@ def test_configmap_apis(self):
client = api_client.ApiClient('http://127.0.0.1:8080/')
api = core_v1_api.CoreV1Api(client)

name = 'test-configmap-' + str(uuid.uuid4())
test_configmap = {
"kind": "ConfigMap",
"apiVersion": "v1",
"metadata": {
"name": "test-configmap",
"name": name,
},
"data": {
"config.json": "{\"command\":\"/usr/bin/mysqld_safe\"}",
Expand All @@ -174,18 +176,18 @@ def test_configmap_apis(self):
resp = api.create_namespaced_config_map(
body=test_configmap, namespace='default'
)
self.assertEqual('test-configmap', resp.metadata.name)
self.assertEqual(name, resp.metadata.name)

resp = api.read_namespaced_config_map(
name='test-configmap', namespace='default')
self.assertEqual('test-configmap', resp.metadata.name)
name=name, namespace='default')
self.assertEqual(name, resp.metadata.name)

test_configmap['data']['config.json'] = "{}"
resp = api.patch_namespaced_config_map(
name='test-configmap', namespace='default', body=test_configmap)
name=name, namespace='default', body=test_configmap)

resp = api.delete_namespaced_config_map(
name='test-configmap', body={}, namespace='default')
name=name, body={}, namespace='default')

resp = api.list_namespaced_config_map('kube-system', pretty=True)
self.assertEqual([], resp.items)
Expand Down

0 comments on commit cf5d796

Please sign in to comment.