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 HelmClient(
            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 HelmClient(
            provider=self.dummy_provider).repositories == repositories_expected
Ejemplo n.º 2
0
 def test_get_version(self):
     with self.assertRaises(HelmVersionException):
         provider_mock = mock.Mock(autospec=HelmProvider)
         provider_mock.execute.side_effect = [
             HelmCmdResponse(1, '', '', None),
             HelmCmdResponse(0, '', 'v3.0.0-alpha.2+g00000', None),
         ]
         client = Helm2Client(provider=provider_mock)
         client._get_version('')
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 HelmClient(
         provider=self.dummy_provider).check_helm_command() == True
     with self.assertRaises(HelmClientException) as e:
         assert HelmClient(
             provider=self.dummy_provider).check_helm_command() == False
Ejemplo n.º 4
0
def mock_execute_unknown_helm_provider(helm_command):
    if helm_command.command == 'version':
        if '--client' in helm_command.arguments:
            return HelmCmdResponse(
                exit_code=1,
                stderr='i am a helm 3 client and i break on --client',
                stdout='',
                command=helm_command,
            )
        return HelmCmdResponse(
            exit_code=0,
            stderr='',
            stdout='not a valid version',
            command=helm_command,
        )
Ejemplo n.º 5
0
def mock_execute_helm3provider(helm_command):
    if helm_command.command == 'version':
        if '--client' in helm_command.arguments:
            return HelmCmdResponse(
                exit_code=1,
                stderr='helm 3 does not accept the --client flag',
                stdout='',
                command=helm_command,
            )
        return HelmCmdResponse(
            exit_code=0,
            stderr='',
            stdout='v3.0.0-beta.3+g5cb923e',
            command=helm_command,
        )
Ejemplo n.º 6
0
    def test_versions_raise_errors(self):
        self.dummy_provider.execute.return_value = HelmCmdResponse(
            0, '', 'invalid', '')

        for versions in ['client_version', 'server_version']:
            with self.assertRaises(HelmClientException):
                getattr(HelmClient(provider=self.dummy_provider), versions)
Ejemplo n.º 7
0
    def test_upgrade(self):
        self.dummy_provider.execute.side_effect = [
            HelmCmdResponse(0, '', 'pass', HelmCommand('install',
                                                       ['--install'])),
            HelmCmdResponse(0, '', 'pass', HelmCommand('install', []))
        ]

        with_install = HelmClient(provider=self.dummy_provider).upgrade(
            [], install=True)
        without_install = HelmClient(provider=self.dummy_provider).upgrade(
            [], install=False)

        assert with_install.command.arguments == ['--install']
        assert without_install.command.command == 'install'
        assert with_install.command.arguments == ['--install']
        assert without_install.command.command == 'install'
Ejemplo n.º 8
0
def mock_execute_helm2provider(helm_command):
    if helm_command.command == 'version':
        if '--server' in helm_command.arguments:
            return HelmCmdResponse(
                exit_code=0,
                stderr='',
                stdout='Server: v2.14.1+g5270352',
                command=helm_command,
            )
        if '--client' in helm_command.arguments:
            return HelmCmdResponse(
                exit_code=0,
                stderr='',
                stdout='Client: v2.13.1+g618447c',
                command=helm_command,
            )
Ejemplo n.º 9
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.º 10
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.º 11
0
 def test_properties(self):
     resp = HelmCmdResponse(0, '', '', '')
     for attr in ['exit_code', 'stdout', 'stderr', 'command']:
         assert getattr(resp, attr) != None
Ejemplo n.º 12
0
 def test_succeeded_method(self):
     assert HelmCmdResponse(0, None, None, None).succeeded == True
     assert HelmCmdResponse(1, None, None, None).succeeded == False
Ejemplo n.º 13
0
 def test_client_version(self):
     self.dummy_provider.execute.return_value = HelmCmdResponse(
         0, '', 'Client: v0.0.0+gabcdef01234', '')
     assert '0.0.0' == HelmClient(
         provider=self.dummy_provider).client_version
Ejemplo n.º 14
0
 def test_tiller_version(self):
     self.dummy_provider.execute.return_value = HelmCmdResponse(
         0, '', 'Server: v0.0.0+gabcdef01234', '')
     assert '0.0.0' == Helm2Client(
         provider=self.dummy_provider).tiller_version
Ejemplo n.º 15
0
    def test_get_cache(self):

        self.dummy_provider.execute.return_value = HelmCmdResponse(
            0, '', '/Users/test/.helm', '')
        assert "/Users/test/.helm" == Helm2Client(
            provider=self.dummy_provider).cache