Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ test-style:

test-unit:
cd rootfs \
&& coverage run manage.py test --settings=api.settings.testing --noinput registry api \
&& coverage run manage.py test --settings=api.settings.testing --noinput registry api scheduler.tests \
&& coverage report -m

test-unit-quick:
cd rootfs \
&& ./manage.py test --settings=api.settings.testing --noinput --parallel ${TEST_PROCS} --noinput registry api
&& ./manage.py test --settings=api.settings.testing --noinput --parallel ${TEST_PROCS} --noinput registry api scheduler.tests

test-functional:
@echo "Implement functional tests in _tests directory"
Expand Down
2 changes: 1 addition & 1 deletion rootfs/scheduler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def _set_container(self, namespace, container_name, data, **kwargs): # noqa

# add in healthchecks
healthchecks = kwargs.get('healthcheck', None)
if healthchecks:
if healthchecks and kwargs.get('routable', False):
# check if a port is present. if not, auto-populate it
# TODO: rip this out when we stop supporting deis config:set HEALTHCHECK_URL
if (
Expand Down
55 changes: 55 additions & 0 deletions rootfs/scheduler/tests/test_scheduler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
Unit tests for the Deis scheduler module.

Run the tests with "./manage.py test scheduler"
"""
from django.core.cache import cache
from django.test import TestCase

from scheduler import mock


class SchedulerTest(TestCase):
"""Tests scheduler calls"""

def setUp(self):
self.scheduler_client = mock.MockSchedulerClient()

def tearDown(self):
# make sure every test has a clean slate for k8s mocking
cache.clear()

def test_set_container_applies_healthcheck_with_routable(self):
"""
Test that when _set_container is called with the 'routable' kwarg set to True,
a healthcheck is attached to the dictionary.
"""
data = {}
healthcheck = {
'livenessProbe': {
'httpGet': {
'port': 80,
}
}
}
self.scheduler_client._set_container('foo',
'bar',
data,
routable=True,
healthcheck=healthcheck)
self.assertDictContainsSubset(healthcheck, data)
# clear the dict to call again with routable as false
data = {}
self.scheduler_client._set_container('foo',
'bar',
data,
routable=False,
healthcheck=healthcheck)
self.assertEqual(data.get('livenessProbe'), None)
# now call without setting 'routable', should default to False
data = {}
self.scheduler_client._set_container('foo',
'bar',
data,
healthcheck=healthcheck)
self.assertEqual(data.get('livenessProbe'), None)