Exemple #1
0
    def test_raises_error_when_any_hook_fails(self, mock_cmd_call, *args):
        """Assert that we raise an error when commands fail and we don't run subsequent commands."""
        good_response = Response(
            exitcode=0,
            stderr='',
            stdout='some info',
            command_string='my --command',
        )
        bad_response = Response(
            exitcode=127,
            stderr='found exit code 127 set in test mock',
            stdout='here would be stdout',
            command_string='mock --command',
        )

        _hook = Hook(['', '', ''], "test_raises_error_when_any_hook_fails", '')

        mock_cmd_call.side_effect = [
            good_response, bad_response, good_response
        ]

        with self.assertRaises(ReckonerCommandException):
            _hook.run()

        self.assertEqual(mock_cmd_call.call_count, 2,
                         "Call two should fail and not run the third hook.")
Exemple #2
0
    def test_support_comparisons(self):
        resp_one = Response('', '', 0, '')
        resp_two = Response('', '', 0, '')
        resp_three = Response('', '', 0, 'notequal')

        self.assertEqual(resp_one, resp_two)
        self.assertNotEqual(resp_one, resp_three)
        self.assertNotEqual(resp_two, resp_three)
Exemple #3
0
    def test_bool(self):
        response = Response('', '', 127, '')
        self.assertFalse(
            response,
            "Any response where exitcode is not 0 should return false")

        response = Response('', '', 0, '')
        self.assertTrue(response,
                        "All responses with exitcode 0 should return True")
Exemple #4
0
    def test_failed_pre_install_hooks_fail_chart_installation(self, configMock, helmClientMock, yamlLoadMock, sysMock, repoMock, chartCallMock):
        """Test that the chart isn't installed when the pre_install hooks return any non-zero responses. This also assures we don't raise python errors with hook errors."""
        c = configMock()
        c.helm_args = ['provided args']
        c.local_development = False

        h = helmClientMock()
        h.client_version = '0.0.1'

        yamlLoadMock.load.return_value = {
            'charts': {
                'first-chart': {
                    'hooks': {
                        'pre_install': [
                            'run a failed command here',
                        ]
                    }
                }
            }
        }

        chartCallMock.return_value = Response(exitcode=1, command_string='mocked', stderr=' ', stdout=' ')

        course = Course(None)
        course.plot(['first-chart'])

        self.assertEqual(chartCallMock.call_count, 1)
        self.assertEqual(len(course.failed_charts), 1, "We should have only one failed chart install due to hook failure.")
Exemple #5
0
    def test_hooks_support_list(self, mock_cmd_call, *args):
        """Assert that hooks can be defined as lists"""
        chart = self.get_chart()
        chart.hooks = {
            'pre_install': [
                'works',
                'twice works',
            ]
        }

        mock_cmd_call.side_effect = [
            Response(command_string='command', stderr='err-output', stdout='output', exitcode=0),
            Response(command_string='command', stderr='err-output', stdout='output', exitcode=0),
        ]
        chart.run_hook('pre_install')
        self.assertTrue(mock_cmd_call.call_count == 2)
Exemple #6
0
 def test_execute_contract(self, call_mock):
     """Expect all the providers to accept a specific method signature and output correct object"""
     for provider in self._list_of_providers:
         helm_cmd = HelmCommand('mocking-helm', ['--debug'])
         call_mock.side_effect = [Response('stdout', 'stderr', 0, None)]
         inst = provider.execute(helm_cmd)
         assert call_mock.assert_called_once
         assert isinstance(inst, HelmCmdResponse)
Exemple #7
0
    def test_hooks_support_list(self, mock_cmd_call, *args):
        """Assert that hooks can be defined as lists"""
        _hook = Hook([
            'works',
            'twice works',
        ], 'test_hooks_support_list')

        mock_cmd_call.side_effect = [
            Response(command_string='command',
                     stderr='err-output',
                     stdout='output',
                     exitcode=0),
            Response(command_string='command',
                     stderr='err-output',
                     stdout='output',
                     exitcode=0),
        ]
        _hook.run()
        self.assertTrue(mock_cmd_call.call_count == 2)
Exemple #8
0
 def test_properties(self):
     required_attrs = {
         'stdout': 'stdout value',
         'stderr': 'stderr value',
         'exitcode': 0,
         'command_string': 'command -that -ran',
     }
     response = Response(**required_attrs)
     for attr, value in list(required_attrs.items()):
         self.assertEqual(getattr(response, attr), value)
Exemple #9
0
    def test_hooks_support_strings(self, mock_cmd_call, *args):
        """Assert that hooks can be defined as a string"""
        chart = self.get_chart()
        chart.hooks = {
            'pre_install': 'works'
        }

        mock_cmd_call.side_effect = [Response(command_string='command', stderr='err-output', stdout='output', exitcode=0)]
        chart.run_hook('pre_install')
        mock_cmd_call.assert_called_once()
Exemple #10
0
    def test_hooks_support_strings(self, mock_cmd_call, *args):
        """Assert that hooks can be defined as a string"""
        _hook = Hook('works', 'test_hooks_support_strings')

        mock_cmd_call.side_effect = [
            Response(command_string='command',
                     stderr='err-output',
                     stdout='output',
                     exitcode=0)
        ]
        _hook.run()
        mock_cmd_call.assert_called_once()
Exemple #11
0
 def test_execution_directory(self, mock_cmd_call, *args):
     """Assert that we're executing in the same directory as the course yml"""
     _path = '/path/where/course/lives/'
     _fake_command = 'fake --command'
     chart = self.get_chart()
     chart.hooks = {
         'pre_install': [
             _fake_command
         ]
     }
     chart.config.course_base_directory = _path
     mock_cmd_call.side_effect = [Response(command_string=_fake_command, stderr='err-output', stdout='output', exitcode=0)]
     chart.run_hook('pre_install')
     mock_cmd_call.assert_called_with(_fake_command, shell=True, executable='/bin/bash', path=_path)
Exemple #12
0
 def test_execution_directory(self, mock_cmd_call, *args):
     """Assert that we're executing in the same directory as the course yml"""
     _path = '/path/where/course/lives/'
     _fake_command = 'fake --command'
     _hook = Hook(_fake_command, 'test_execution_directory_hook', _path)
     mock_cmd_call.side_effect = [
         Response(command_string=_fake_command,
                  stderr='err-output',
                  stdout='output',
                  exitcode=0)
     ]
     _hook.run()
     mock_cmd_call.assert_called_with(_fake_command,
                                      shell=True,
                                      executable='/bin/bash',
                                      path=_path)
Exemple #13
0
 def test_support_str(self):
     resp = Response('', '', 0, '')
     self.assertEqual(resp.__str__(), "{'stdout': '', 'stderr': '', 'exitcode': 0, 'command_string': ''}")