Example #1
0
    def test_plugin_should_create_tag_for_given_name(self):
        # given
        tag_name = 'hello-tag'
        action = CreateGitTag(
            tag=tag_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 tag_name in repo.tags

        finally:
            # cleanup
            repo = git.Repo(self.repo_path())
            self.remove_tag_from_origin(tag_name, repo)
Example #2
0
    def test_plugin_should_checkout_master_branch(self):
        # given
        tag_name = 'hello-tag'
        action = CreateGitTag(
            tag=tag_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_tag_from_origin(tag_name, repo)
Example #3
0
    def test_plugin_creates_remote_for_given_tag_name(self):
        # given
        tag_name = 'hello-tag'
        action = CreateGitTag(
            tag=tag_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
            assert tag_name in origin.repo.refs
            assert origin.repo.refs[tag_name].__class__ is git.TagReference

        finally:
            # cleanup
            repo = git.Repo(self.repo_path())
            self.remove_tag_from_origin(tag_name, repo)
Example #4
0
    def test_plugin_uses_existing_repo(self):
        # given
        tag_name = 'hello-tag'
        action = CreateGitTag(
            tag=tag_name, repo_dir=self.repo_path(),
            from_branch='master', use_existing=True
        )

        # (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()
        )

        # when
        action.execute(self.jenkins_job)

        # then
        assert tag_name in repo.tags

        # cleanup
        self.remove_tag_from_origin(tag_name, repo)
Example #5
0
    def test_plugin_creates_directory_if_not_exists(self):
        # given
        tag_name = 'hello-tag'
        action = CreateGitTag(
            tag=tag_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)

        # when
        try:
            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_tag_from_origin(tag_name, repo)