From f7e4ae7e8b0def53d765182596ceb1f8973b2511 Mon Sep 17 00:00:00 2001 From: Steve Tooke Date: Fri, 10 Nov 2023 17:34:22 +0000 Subject: [PATCH] Add a failing test for pulling jira reference from branch --- cmd/kosli/reportEvidenceCommitJira_test.go | 5 +++++ internal/testHelpers/testHelpers.go | 8 ++++++++ 2 files changed, 13 insertions(+) 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), + }) +}