diff --git a/cmd/kosli/reportEvidenceCommitJira_test.go b/cmd/kosli/reportEvidenceCommitJira_test.go index 6c4178734..3cd17329d 100644 --- a/cmd/kosli/reportEvidenceCommitJira_test.go +++ b/cmd/kosli/reportEvidenceCommitJira_test.go @@ -49,6 +49,7 @@ func (suite *CommitEvidenceJiraCommandTestSuite) TearDownSuite() { type jiraTestsAdditionalConfig struct { commitMessage string + branchName string } func (suite *CommitEvidenceJiraCommandTestSuite) TestCommitEvidenceJiraCommandCmd() { @@ -163,6 +164,10 @@ func (suite *CommitEvidenceJiraCommandTestSuite) TestCommitEvidenceJiraCommandCm } for _, test := range tests { if test.additionalConfig != nil { + branchName := test.additionalConfig.(jiraTestsAdditionalConfig).branchName + if branchName != "" { + testHelpers.CheckoutNewBranch(suite.workTree, branchName) + } msg := test.additionalConfig.(jiraTestsAdditionalConfig).commitMessage commitSha, err := testHelpers.CommitToRepo(suite.workTree, suite.fs, msg) require.NoError(suite.T(), err) diff --git a/internal/testHelpers/testHelpers.go b/internal/testHelpers/testHelpers.go index 1e5224dec..3737f4c26 100644 --- a/internal/testHelpers/testHelpers.go +++ b/internal/testHelpers/testHelpers.go @@ -2,6 +2,7 @@ package testHelpers import ( "fmt" + "github.com/go-git/go-git/v5/plumbing" "os" "path/filepath" "testing" @@ -77,3 +78,10 @@ func CommitToRepo(w *git.Worktree, fs billy.Filesystem, commitMessage string) (s return hash.String(), nil } + +func CheckoutNewBranch(w *git.Worktree, branchName string) error { + return w.Checkout(&git.CheckoutOptions{ + Create: true, + Branch: plumbing.ReferenceName(branchName), + }) +}