Ejemplo n.º 1
0
    def test_plugin_should_create_branch_for_given_name(self):
        # given
        branch_name = "test-branch1"
        action = CreateGitBranch(branch=branch_name, repo_dir=self.repo_dir, from_branch="master", use_existing=False)

        try:
            # when
            action.execute(jenkins_job=self.jenkins_job)
            repo = git.Repo(self.repo_path())

            # then
            assert branch_name in repo.heads

        finally:
            # cleanup
            repo = git.Repo(self.repo_path())
            self.remove_branch_from_origin(branch_name, repo)
Ejemplo n.º 2
0
    def test_plugin_should_checkout_master_branch(self):
        # given
        branch_name = "test-branch1"
        action = CreateGitBranch(branch=branch_name, repo_dir=self.repo_dir, from_branch="master", use_existing=False)

        try:
            # when
            action.execute(jenkins_job=self.jenkins_job)
            repo = git.Repo(self.repo_path())
            head_name = repo.head.reference.name

            # then
            assert head_name == "master"

        finally:
            # cleanup
            repo = git.Repo(self.repo_path())
            self.remove_branch_from_origin(branch_name, repo)
Ejemplo n.º 3
0
    def test_plugin_creates_remote_for_given_branch_name(self):
        # given
        branch_name = "test-branch1"
        action = CreateGitBranch(branch=branch_name, repo_dir=self.repo_dir, from_branch="master", use_existing=False)

        try:
            # when
            action.execute(jenkins_job=self.jenkins_job)
            repo = git.Repo(self.repo_path())
            origin = repo.remotes["origin"]

            # then
            ref = "origin/%s" % branch_name
            assert ref in [ref.name for ref in origin.refs]

        finally:
            # cleanup
            repo = git.Repo(self.repo_path())
            self.remove_branch_from_origin(branch_name, repo)
Ejemplo n.º 4
0
    def test_plugin_uses_existing_repo(self):
        # given
        branch_name = "test-branch1"
        action = CreateGitBranch(branch=branch_name, repo_dir=self.repo_path(), from_branch="master", use_existing=True)

        try:
            # when (repository should not exist when tests start
            # - we are testing in a clean environment)
            repo = git.Repo.clone_from(self.jenkins_job.get_scm_url(), self.repo_path())

            action.execute(self.jenkins_job)

            # then
            assert branch_name in repo.heads

        finally:
            # cleanup
            repo = git.Repo(self.repo_path())
            self.remove_branch_from_origin(branch_name, repo)
Ejemplo n.º 5
0
    def test_plugin_creates_directory_if_not_exists(self):
        # given
        branch_name = "test-branch1"
        action = CreateGitBranch(branch=branch_name, repo_dir=self.repo_dir, from_branch="master", use_existing=False)

        # make sure that repo directory does not exist
        if os.path.exists(self.repo_dir) and os.path.isdir(self.repo_dir):
            shutil.rmtree(self.repo_dir)

        try:
            # when
            action.execute(jenkins_job=self.jenkins_job)

            # then
            assert os.path.exists(self.repo_path())
            assert os.path.isdir(self.repo_path())

        finally:
            # cleanup
            repo = git.Repo(self.repo_path())
            self.remove_branch_from_origin(branch_name, repo)