Skip to content

Commit

Permalink
test(kubehttpclient) add .version() behavior test
Browse files Browse the repository at this point in the history
  • Loading branch information
ess committed Aug 5, 2019
1 parent 2e96837 commit 0e840b4
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions rootfs/scheduler/tests/test_kubehttpclient_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"""
Unit tests for the Deis scheduler module.
Run the tests with "./manage.py test scheduler"
"""
import requests
import requests_mock
from unittest import mock
from packaging.version import parse

from django.test import TestCase

import scheduler


def mock_session_for_version(blah=None):
return requests.Session()


def connection_refused_matcher(request):
raise requests.ConnectionError("connection refused")


@mock.patch('scheduler.get_session', mock_session_for_version)
class KubeHTTPClientTest(TestCase):
"""Tests kubernetes HTTP client version calls"""

def setUp(self):
self.adapter = requests_mock.Adapter()
self.url = 'http://versiontest.example.com'
self.path = '/version'

# use the real scheduler client.
self.scheduler = scheduler.KubeHTTPClient(self.url)
self.scheduler.session.mount(self.url, self.adapter)

def test_version_for_gke(self):
"""
Ensure that version() sanitizes info from GKE clusters
"""

cases = {
"1.12": {"major": "1", "minor": "12-gke"},
"1.10": {"major": "1", "minor": "10-gke"},
"1.9": {"major": "1", "minor": "9-gke"},
"1.8": {"major": "1", "minor": "8-gke"},
}

for canonical in cases:
resp = cases[canonical]
self.adapter.register_uri('GET', self.url + self.path, json=resp)

expected = parse(canonical)
actual = self.scheduler.version()

self.assertEqual(expected, actual, "{} breaks".format(resp))

def test_version_for_eks(self):
"""
Ensure that version() sanitizes info from EKS clusters
"""

cases = {
"1.12": {"major": "1", "minor": "12+"},
"1.10": {"major": "1", "minor": "10+"},
"1.9": {"major": "1", "minor": "9+"},
"1.8": {"major": "1", "minor": "8+"},
}

for canonical in cases:
resp = cases[canonical]
self.adapter.register_uri('GET', self.url + self.path, json=resp)

expected = parse(canonical)
actual = self.scheduler.version()

self.assertEqual(expected, actual, "{} breaks".format(resp))

def test_version_vanilla(self):
"""
Ensure that version() sanitizes info from vanilla k8s clusters
"""

cases = {
"1.12": {"major": "1", "minor": "12"},
"1.10": {"major": "1", "minor": "10"},
"1.9": {"major": "1", "minor": "9"},
"1.8": {"major": "1", "minor": "8"},
}

for canonical in cases:
resp = cases[canonical]
self.adapter.register_uri('GET', self.url + self.path, json=resp)

expected = parse(canonical)
actual = self.scheduler.version()

self.assertEqual(expected, actual, "{} breaks".format(resp))

0 comments on commit 0e840b4

Please sign in to comment.