mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
extract settings function in unit tests
This commit is contained in:
parent
453b3d26a6
commit
db91ed06ee
@ -140,18 +140,24 @@ class KubernetesTestCase(TestCase, LoaderModuleMockMixin):
|
|||||||
kubernetes.kubernetes.client.ExtensionsV1beta1Api().
|
kubernetes.kubernetes.client.ExtensionsV1beta1Api().
|
||||||
create_namespaced_deployment().to_dict.called)
|
create_namespaced_deployment().to_dict.called)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def settings(name, value=None):
|
||||||
|
'''
|
||||||
|
Test helper
|
||||||
|
:return: settings or default
|
||||||
|
'''
|
||||||
|
data = {
|
||||||
|
'kubernetes.kubeconfig': '/home/testuser/.minikube/kubeconfig.cfg',
|
||||||
|
'kubernetes.context': 'minikube'
|
||||||
|
}
|
||||||
|
return data.get(name, value)
|
||||||
|
|
||||||
|
|
||||||
def test_setup_kubeconfig_file(self):
|
def test_setup_kubeconfig_file(self):
|
||||||
'''
|
'''
|
||||||
Test that the `kubernetes.kubeconfig` configuration isn't overwritten
|
Test that the `kubernetes.kubeconfig` configuration isn't overwritten
|
||||||
:return:
|
:return:
|
||||||
'''
|
'''
|
||||||
def settings(name, value=None):
|
|
||||||
data = {
|
|
||||||
'kubernetes.kubeconfig': '/home/testuser/.minikube/kubeconfig.cfg',
|
|
||||||
'kubernetes.context': 'minikube'
|
|
||||||
}
|
|
||||||
return data.get(name, value)
|
|
||||||
|
|
||||||
with mock_kubernetes_library() as mock_kubernetes_lib:
|
with mock_kubernetes_library() as mock_kubernetes_lib:
|
||||||
with patch.dict(kubernetes.__salt__, {'config.option': Mock(side_effect=settings)}):
|
with patch.dict(kubernetes.__salt__, {'config.option': Mock(side_effect=settings)}):
|
||||||
mock_kubernetes_lib.config.load_kube_config = Mock()
|
mock_kubernetes_lib.config.load_kube_config = Mock()
|
||||||
@ -167,13 +173,6 @@ class KubernetesTestCase(TestCase, LoaderModuleMockMixin):
|
|||||||
by provided kubeconfig_data in the command
|
by provided kubeconfig_data in the command
|
||||||
:return:
|
:return:
|
||||||
'''
|
'''
|
||||||
def settings(name, value=None):
|
|
||||||
data = {
|
|
||||||
'kubernetes.kubeconfig': '/home/testuser/.minikube/kubeconfig.cfg',
|
|
||||||
'kubernetes.context': 'minikube'
|
|
||||||
}
|
|
||||||
return data.get(name, value)
|
|
||||||
|
|
||||||
with mock_kubernetes_library() as mock_kubernetes_lib:
|
with mock_kubernetes_library() as mock_kubernetes_lib:
|
||||||
with patch.dict(kubernetes.__salt__, {'config.option': Mock(side_effect=settings)}):
|
with patch.dict(kubernetes.__salt__, {'config.option': Mock(side_effect=settings)}):
|
||||||
mock_kubernetes_lib.config.load_kube_config = Mock()
|
mock_kubernetes_lib.config.load_kube_config = Mock()
|
||||||
|
Loading…
Reference in New Issue
Block a user