def test_fetch_project_passes_depth_parameter_for_shallow_clone_configuration(
            self, shallow_clone):
        Configuration['shallow_clones'] = shallow_clone
        self.os_path_isfile_mock.return_value = False
        self.os_path_exists_mock.return_value = False
        mock_popen = self._patch_popen(
            {'git rev-parse$': _FakePopenResult(return_code=1)})

        git = Git(
            url='http://original-user-specified-url.test/repo-path/repo-name')
        git.fetch_project()

        git_clone_call = call(AnyStringMatching('git clone --depth=1'),
                              start_new_session=ANY,
                              stdout=ANY,
                              stderr=ANY,
                              cwd=ANY,
                              shell=ANY)
        if shallow_clone:
            self.assertIn(
                git_clone_call, mock_popen.call_args_list,
                'If shallow cloning, the --depth=1 parameter '
                'should be present.')
        else:
            self.assertNotIn(
                git_clone_call, mock_popen.call_args_list,
                'If deep cloning, the --depth=1 parameter '
                'must be absent.')
    def test_repo_is_cloned_if_and_only_if_rev_parse_fails(
            self, rev_parse_return_code, expect_git_clone_call):
        mock_popen = self._patch_popen({
            'git rev-parse$':
            _FakePopenResult(return_code=rev_parse_return_code)
        })
        Configuration['repo_directory'] = '/repo-directory'

        git = Git(
            url='http://original-user-specified-url.test/repo-path/repo-name')
        git.fetch_project()

        git_clone_call = call(AnyStringMatching('git clone'),
                              start_new_session=ANY,
                              stdout=ANY,
                              stderr=ANY,
                              cwd=ANY,
                              shell=ANY)
        if expect_git_clone_call:
            self.assertIn(
                git_clone_call, mock_popen.call_args_list,
                'If "git rev-parse" returns a failing exit code, '
                '"git clone" should be called.')
        else:
            self.assertNotIn(
                git_clone_call, mock_popen.call_args_list,
                'If "git rev-parse" returns a successful exit '
                'code, "git clone" should not be called.')
    def test_slave_param_overrides_returns_expected(self):
        self._patch_popen({
            'git rev-parse FETCH_HEAD': _FakePopenResult(stdout='deadbee123\n')
        })
        Configuration['repo_directory'] = '/repo-directory'

        git = Git(url='http://original-user-specified-url.test/repo-path/repo-name')
        git.fetch_project()
        actual_overrides = git.slave_param_overrides()

        expected_overrides = {
            'url': 'ssh://fake_hostname/repodirectory/originaluserspecifiedurl.test/repopath/reponame',
            'branch': 'refs/clusterrunner/deadbee123',
        }
        self.assertEqual(expected_overrides, actual_overrides, 'Slave param overrides from Git object should match'
                                                               'expected.')
Exemple #4
0
    def test_fetch_project_passes_depth_parameter_for_shallow_clone_configuration(self, shallow_clone):
        Configuration['shallow_clones'] = shallow_clone
        self.os_path_isfile_mock.return_value = False
        self.os_path_exists_mock.return_value = False
        mock_popen = self._patch_popen({'git rev-parse$': _FakePopenResult(return_code=1)})

        git = Git(url='http://original-user-specified-url.test/repo-path/repo-name')
        git.fetch_project()

        git_clone_call = call(AnyStringMatching('git clone --depth=1'), start_new_session=ANY,
                              stdout=ANY, stderr=ANY, cwd=ANY, shell=ANY)
        if shallow_clone:
            self.assertIn(git_clone_call, mock_popen.call_args_list, 'If shallow cloning, the --depth=1 parameter '
                                                                     'should be present.')
        else:
            self.assertNotIn(git_clone_call, mock_popen.call_args_list, 'If deep cloning, the --depth=1 parameter '
                                                                        'must be absent.')
Exemple #5
0
    def test_repo_is_cloned_if_and_only_if_rev_parse_fails(self, rev_parse_return_code, expect_git_clone_call):
        mock_popen = self._patch_popen({
            'git rev-parse$': _FakePopenResult(return_code=rev_parse_return_code)
        })
        Configuration['repo_directory'] = '/repo-directory'

        git = Git(url='http://original-user-specified-url.test/repo-path/repo-name')
        git.fetch_project()

        git_clone_call = call(AnyStringMatching('git clone'), start_new_session=ANY,
                              stdout=ANY, stderr=ANY, cwd=ANY, shell=ANY)
        if expect_git_clone_call:
            self.assertIn(git_clone_call, mock_popen.call_args_list, 'If "git rev-parse" returns a failing exit code, '
                                                                     '"git clone" should be called.')
        else:
            self.assertNotIn(git_clone_call, mock_popen.call_args_list, 'If "git rev-parse" returns a successful exit '
                                                                        'code, "git clone" should not be called.')
Exemple #6
0
    def test_slave_param_overrides_returns_expected(self):
        Configuration['get_project_from_master'] = True
        Configuration['repo_directory'] = '/repo-directory'
        self._patch_popen({
            'git rev-parse FETCH_HEAD': _FakePopenResult(stdout='deadbee123\n')
        })

        git = Git(url='http://original-user-specified-url.test/repo-path/repo-name')
        git.fetch_project()
        actual_overrides = git.slave_param_overrides()

        expected_overrides = {
            'url': 'ssh://fake_hostname/repodirectory/originaluserspecifiedurl.test/repopath/reponame',
            'branch': 'refs/clusterrunner/deadbee123',
        }
        self.assertEqual(expected_overrides, actual_overrides, 'Slave param overrides from Git object should match'
                                                               'expected.')
Exemple #7
0
    def test_slave_param_overrides_returns_expected(self):
        self._patch_popen({
            'git rev-parse FETCH_HEAD':
            _FakePopenResult(stdout='deadbee123\n')
        })
        self.patch('app.project_type.git.os.path.exists').return_value = False
        self.patch('app.project_type.git.os.path.isfile').return_value = False
        self.patch('app.project_type.git._GitRemoteCommandExecutor')
        Configuration['repo_directory'] = '/repo-directory'

        git = Git(
            url='http://original-user-specified-url.test/repo-path/repo-name')
        git.fetch_project()
        actual_overrides = git.slave_param_overrides()

        expected_overrides = {
            'url':
            'ssh://fake_hostname/repodirectory/originaluserspecifiedurl.test/repopath/reponame',
            'branch': 'refs/clusterrunner/deadbee123',
        }
        self.assertEqual(
            expected_overrides, actual_overrides,
            'Slave param overrides from Git object should match'
            'expected.')