Ejemplo n.º 1
0
    def test_repositories(self):
        repositories_string = """NAME            URL
stable          https://kubernetes-charts.storage.googleapis.com
local           http://127.0.0.1:8879/charts
test_repo       https://kubernetes-charts.storage.googleapis.com
incubator       https://kubernetes-charts-incubator.storage.googleapis.com"""

        repositories_expected = ['stable', 'local', 'test_repo', 'incubator']

        self.dummy_provider.execute.return_value = HelmCmdResponse(
            0,
            '',
            repositories_string,
            '',
        )

        assert Helm3Client(
            provider=self.dummy_provider).repositories == repositories_expected

        repositories_string_extra_lines = """
NAME            URL
stable          https://kubernetes-charts.storage.googleapis.com
local           http://127.0.0.1:8879/charts

test_repo       https://kubernetes-charts.storage.googleapis.com
incubator       https://kubernetes-charts-incubator.storage.googleapis.com

"""
        self.dummy_provider.execute.return_value = HelmCmdResponse(
            0, '', repositories_string_extra_lines, '')

        assert Helm3Client(
            provider=self.dummy_provider).repositories == repositories_expected
Ejemplo n.º 2
0
    def test_verify_default_helm_args_intantiate(self):
        # Should support instantiate with None
        assert Helm3Client(provider=self.dummy_provider,
                           default_helm_arguments=None)

        # Should raise errors on all other non iterators
        for invalid in [str('invalid'), 1, 0.01, True]:
            with self.assertRaises(ValueError):
                Helm3Client(default_helm_arguments=invalid)
Ejemplo n.º 3
0
 def test_check_helm_command(self):
     self.dummy_provider.execute.side_effect = [
         HelmCmdResponse(0, None, None, None),
         HelmCmdResponse(127, None, None, None)
     ]
     assert Helm3Client(
         provider=self.dummy_provider).check_helm_command() == True
     with self.assertRaises(HelmClientException) as e:
         assert Helm3Client(
             provider=self.dummy_provider).check_helm_command() == False
Ejemplo n.º 4
0
    def test_version_regex(self):
        invalid = [
            'not valid',
        ]

        valid = [('v3.0+unreleased+g30525d7', '3.0'),
                 ('v3.0.0-alpha.2+g97e7461', '3.0.0'),
                 ('v3.0.0-beta.3+g5cb923e', '3.0.0')]
        for stdout in invalid:
            assert Helm3Client(
                provider=self.dummy_provider)._find_version(stdout) == None

        for stdout, expected in valid:
            assert Helm3Client(
                provider=self.dummy_provider)._find_version(stdout) == expected
Ejemplo n.º 5
0
    def test_versions_raise_errors(self):
        self.dummy_provider.execute.return_value = HelmCmdResponse(
            0, '', 'invalid', '')

        for versions in ['version']:
            with self.assertRaises(HelmClientException):
                getattr(Helm3Client(provider=self.dummy_provider), versions)
Ejemplo n.º 6
0
    def test_upgrade(self):
        Helm3Client(provider=self.dummy_provider).upgrade([], install=True)
        self.dummy_provider.execute.called_once()
        self.assertEqual(self.dummy_provider.execute.call_args[0][0].command,
                         "upgrade")
        self.assertEqual(self.dummy_provider.execute.call_args[0][0].arguments,
                         ["--install"])
        self.dummy_provider.reset_mock()

        Helm3Client(provider=self.dummy_provider).upgrade([], install=False)
        self.dummy_provider.execute.called_once()
        self.assertEqual(self.dummy_provider.execute.call_args[0][0].command,
                         "upgrade")
        self.assertEqual(self.dummy_provider.execute.call_args[0][0].arguments,
                         [])
        self.dummy_provider.reset_mock()
Ejemplo n.º 7
0
 def test_get_version(self):
     with self.assertRaises(HelmClientException):
         provider_mock = mock.Mock(autospec=HelmProvider)
         provider_mock.execute.side_effect = [
             HelmCmdResponse(1, '', '', None),
         ]
         client = Helm3Client(provider=provider_mock)
         client._get_version()
Ejemplo n.º 8
0
 def test_default_upgrade_calls_install_flag(self):
     Helm3Client(provider=self.dummy_provider).upgrade([])
     self.dummy_provider.execute.called_once()
     self.assertEqual(self.dummy_provider.execute.call_args[0][0].command,
                      "upgrade")
     self.assertEqual(self.dummy_provider.execute.call_args[0][0].arguments,
                      ["--install"])
     self.dummy_provider.reset_mock()
Ejemplo n.º 9
0
    def test_public_methods(self):
        helm_client = Helm3Client(provider=self.dummy_provider)
        methods = [
            'execute',
            'check_helm_command',
            'upgrade',
        ]

        for method in methods:
            assert hasattr(helm_client, method)
Ejemplo n.º 10
0
    def test_execute_with_additional_parameters(self):
        default_params = ['--some params']
        adhoc_params = ['--some more']
        expected_params = default_params + adhoc_params

        Helm3Client(default_helm_arguments=default_params,
                    provider=self.dummy_provider).execute(
                        'version', adhoc_params)

        assert self.dummy_provider.execute.call_args[0][
            0].arguments == expected_params
Ejemplo n.º 11
0
    def test_execute_with_default_helm_arguments(self):
        expected_params = ['--some params', '--found']
        helm_client = Helm3Client(provider=self.dummy_provider)
        helm_client.default_helm_arguments = expected_params

        helm_client.execute('help')

        self.dummy_provider.execute.assert_called_once
        assert isinstance(self.dummy_provider.execute.call_args[0][0],
                          HelmCommand)
        assert self.dummy_provider.execute.call_args[0][
            0].arguments == expected_params
Ejemplo n.º 12
0
    def test_upgrade_with_plugin(self):
        plugin_name = 'some-plugin'

        Helm3Client(provider=self.dummy_provider).upgrade([],
                                                          install=True,
                                                          plugin=plugin_name)
        self.dummy_provider.execute.assert_called_once()

        self.assertEqual(self.dummy_provider.execute.call_args[0][0].command,
                         plugin_name)
        self.assertEqual(self.dummy_provider.execute.call_args[0][0].arguments,
                         ["upgrade", "--install"])

        self.dummy_provider.reset_mock()

        Helm3Client(provider=self.dummy_provider).upgrade([],
                                                          install=False,
                                                          plugin=plugin_name)
        self.dummy_provider.execute.assert_called_once()

        self.assertEqual(self.dummy_provider.execute.call_args[0][0].command,
                         plugin_name)
        self.assertEqual(self.dummy_provider.execute.call_args[0][0].arguments,
                         ["upgrade"])
Ejemplo n.º 13
0
    def test_get_cache(self):
        env_response = """
HELM_BIN="/Users/test/.asdf/installs/helm/3.2.4/bin/helm"
HELM_DEBUG="false"
HELM_KUBEAPISERVER=""
HELM_KUBECONTEXT=""
HELM_KUBETOKEN=""
HELM_NAMESPACE="default"
HELM_PLUGINS="/Users/testLibrary/helm/plugins"
HELM_REGISTRY_CONFIG="/Users/test/Library/Preferences/helm/registry.json"
HELM_REPOSITORY_CACHE="/Users/test/Library/Caches/helm/repository"
HELM_REPOSITORY_CONFIG="/Users/test/Library/Preferences/helm/repositories.yaml
"""
        self.dummy_provider.execute.return_value = HelmCmdResponse(
            0, '', env_response, '')
        assert "/Users/test/Library/Caches/helm/repository" == Helm3Client(
            provider=self.dummy_provider).cache
Ejemplo n.º 14
0
 def test_default_helm_arguments(self):
     helm_client = Helm3Client(provider=self.dummy_provider)
     assert hasattr(helm_client, 'default_helm_arguments')
Ejemplo n.º 15
0
 def test_version(self):
     self.dummy_provider.execute.return_value = HelmCmdResponse(
         0, '', 'v0.0.0+gabcdef01234', '')
     assert '0.0.0' == Helm3Client(provider=self.dummy_provider).version
Ejemplo n.º 16
0
 def test_rollback(self):
     with self.assertRaises(NotImplementedError):
         Helm3Client(provider=self.dummy_provider).rollback('broken')
Ejemplo n.º 17
0
 def test_dependency_update(self):
     Helm3Client(
         provider=self.dummy_provider).dependency_update('chart_path')
     self.dummy_provider.execute.assert_called_once
Ejemplo n.º 18
0
 def test_repo_update(self):
     Helm3Client(provider=self.dummy_provider).repo_update()
     self.dummy_provider.execute.assert_called_once
Ejemplo n.º 19
0
 def test_repo_add(self):
     Helm3Client(provider=self.dummy_provider).repo_add('new', 'url')
     self.dummy_provider.execute.assert_called_once