Skip to content

Commit 465c580

Browse files
authored
Merge pull request #1283 from kris-nova/ingress-unit-tests
chore(ingress): Adding unit tests
2 parents 092e8fe + 960e899 commit 465c580

3 files changed

Lines changed: 56 additions & 2 deletions

File tree

rootfs/scheduler/mock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _acquire(self):
8080
resources = [
8181
'namespaces', 'nodes', 'pods', 'replicationcontrollers',
8282
'secrets', 'services', 'events', 'deployments', 'replicasets',
83-
'horizontalpodautoscalers', 'scale', 'resourcequotas'
83+
'horizontalpodautoscalers', 'scale', 'resourcequotas', 'ingresses'
8484
]
8585

8686

rootfs/scheduler/resources/ingress.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def create(self, ingress, namespace, hostname):
5555
return response
5656

5757
def delete(self, namespace, ingress):
58-
url = self.api("/namespaces/{}/ingresses/{}", namespace, ingress)
58+
url = "/apis/extensions/v1beta1/namespaces/%s/ingresses/%s" % (namespace, ingress)
5959
response = self.http_delete(url)
6060
if self.unhealthy(response.status_code):
6161
raise KubeHTTPException(response, 'delete Ingress "{}"', namespace)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
Unit tests for the Deis ingress module.
3+
4+
Run the tests with './manage.py test ingress'
5+
"""
6+
from scheduler import KubeHTTPException
7+
from scheduler.tests import TestCase
8+
9+
10+
class IngressTest(TestCase):
11+
"""Tests scheduler ingress calls"""
12+
13+
def test_create_ingress(self):
14+
# Ingress assumes that the namespace and ingress name are always the same
15+
self.scheduler.ns.create("test-ingress")
16+
self.scheduler.ingress.create("test-ingress", "test-ingress", "test-ingress")
17+
18+
def test_get_ingresses(self):
19+
response = self.scheduler.ingress.get()
20+
data = response.json()
21+
self.assertEqual(response.status_code, 200, data)
22+
self.assertIn('items', data)
23+
24+
def test_get_ingress(self):
25+
with self.assertRaises(
26+
KubeHTTPException,
27+
msg="failed to get Ingress doesnotexist: 404 Not Found"
28+
):
29+
self.scheduler.ingress.get('doesnotexist')
30+
31+
self.scheduler.ns.create("test-ingress-create")
32+
self.scheduler.ingress.create("test-ingress-create",
33+
"test-ingress-create", "test-ingress-create")
34+
response = self.scheduler.ingress.get("test-ingress-create")
35+
data = response.json()
36+
37+
self.assertEqual(response.status_code, 200, data)
38+
self.assertEqual(data['apiVersion'], 'extensions/v1beta1')
39+
self.assertEqual(data['kind'], 'Ingress')
40+
41+
def test_delete_failure(self):
42+
# test failure
43+
with self.assertRaises(
44+
KubeHTTPException,
45+
msg="failed to delete Ingress doesnotexist: 404 Not Found"
46+
):
47+
self.scheduler.ns.delete('doesnotexist')
48+
49+
def test_delete_namespace(self):
50+
self.scheduler.ns.create("test-ingress-delete")
51+
self.scheduler.ingress.create("test-ingress-delete",
52+
"test-ingress-delete", "test-ingress-delete")
53+
response = self.scheduler.ingress.delete("test-ingress-delete", "test-ingress-delete")
54+
self.assertEqual(response.status_code, 200, response.json())

0 commit comments

Comments
 (0)