Merge pull request #2741 from ecordell/hotfix/kubernetes-secret
Update the expected response layout for kubernetes config
This commit is contained in:
commit
66737ce4ae
2 changed files with 45 additions and 2 deletions
|
@ -57,16 +57,22 @@ class KubernetesConfigProvider(FileConfigProvider):
|
|||
|
||||
def volume_file_exists(self, filename):
|
||||
secret = self._lookup_secret()
|
||||
if not secret:
|
||||
return False
|
||||
return filename in secret
|
||||
|
||||
|
||||
def list_volume_directory(self, path):
|
||||
secret = self._lookup_secret()
|
||||
|
||||
if not secret:
|
||||
return []
|
||||
|
||||
paths = []
|
||||
for filename in secret:
|
||||
if filename.startswith(path):
|
||||
paths.append(filename[len(path) + 1:])
|
||||
return paths
|
||||
|
||||
def remove_volume_file(self, filename):
|
||||
super(KubernetesConfigProvider, self).remove_volume_file(filename)
|
||||
|
@ -126,8 +132,10 @@ class KubernetesConfigProvider(FileConfigProvider):
|
|||
response = self._execute_k8s_api('GET', secret_url)
|
||||
if response.status_code != 200:
|
||||
return None
|
||||
|
||||
return json.loads(response.text)
|
||||
secret_resp = json.loads(response.text)
|
||||
if "data" not in secret_resp:
|
||||
return secret_resp
|
||||
return secret_resp["data"]
|
||||
|
||||
def _execute_k8s_api(self, method, relative_url, data=None):
|
||||
headers = {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import pytest
|
||||
from mock import Mock
|
||||
|
||||
from util.config.provider import KubernetesConfigProvider
|
||||
|
||||
|
@ -9,6 +10,7 @@ class TestKubernetesConfigProvider(KubernetesConfigProvider):
|
|||
def __init__(self):
|
||||
self.yaml_filename = 'yaml_filename'
|
||||
self._service_token = 'service_token'
|
||||
self._execute_k8s_api = Mock()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('directory,filename,expected', [
|
||||
|
@ -23,3 +25,36 @@ def test_get_volume_path(directory, filename, expected):
|
|||
assert expected == provider.get_volume_path(directory, filename)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('response,expected', [
|
||||
(Mock(text="{\"license\":\"test\"}", status_code=200), {"license":"test"}),
|
||||
(Mock(text="{\"data\": {\"license\":\"test\"}}", status_code=200), {"license":"test"}),
|
||||
(Mock(text="{\"data\": {\"license\":\"test\"}}", status_code=404), None),
|
||||
])
|
||||
def test_lookup_secret(response, expected):
|
||||
provider = TestKubernetesConfigProvider()
|
||||
provider._execute_k8s_api.return_value = response
|
||||
assert expected == provider._lookup_secret()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('response,key,expected', [
|
||||
(Mock(text="{\"license\":\"test\"}", status_code=200), "license", True),
|
||||
(Mock(text="{\"data\": {\"license\":\"test\"}}", status_code=200), "license", True),
|
||||
(Mock(text="{\"license\":\"test\"}", status_code=200), "config.yaml", False),
|
||||
(Mock(text="{\"data\": {\"license\":\"test\"}}", status_code=200), "config.yaml", False),
|
||||
(Mock(text="", status_code=404), "license", False),
|
||||
])
|
||||
def test_volume_file_exists(response, key, expected):
|
||||
provider = TestKubernetesConfigProvider()
|
||||
provider._execute_k8s_api.return_value = response
|
||||
assert expected == provider.volume_file_exists(key)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('response,expected', [
|
||||
(Mock(text="{\"extra_license\":\"test\"}", status_code=200), ["license"]),
|
||||
(Mock(text="{\"data\": {\"extra_license\":\"test\"}}", status_code=200), ["license"]),
|
||||
(Mock(text="", status_code=404), []),
|
||||
])
|
||||
def test_list_volume_directory(response, expected):
|
||||
provider = TestKubernetesConfigProvider()
|
||||
provider._execute_k8s_api.return_value = response
|
||||
assert expected == provider.list_volume_directory("extra")
|
Reference in a new issue