Skip to content

Commit

Permalink
Add a failing test for pulling jira reference from branch
Browse files Browse the repository at this point in the history
  • Loading branch information
tooky committed Nov 10, 2023
1 parent 630e998 commit f7e4ae7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/kosli/reportEvidenceCommitJira_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (suite *CommitEvidenceJiraCommandTestSuite) TearDownSuite() {

type jiraTestsAdditionalConfig struct {
commitMessage string
branchName string
}

func (suite *CommitEvidenceJiraCommandTestSuite) TestCommitEvidenceJiraCommandCmd() {
Expand Down Expand Up @@ -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)

Check failure on line 169 in cmd/kosli/reportEvidenceCommitJira_test.go

View workflow job for this annotation

GitHub Actions / test / Lint & Test

Error return value of `testHelpers.CheckoutNewBranch` is not checked (errcheck)
}
msg := test.additionalConfig.(jiraTestsAdditionalConfig).commitMessage
commitSha, err := testHelpers.CommitToRepo(suite.workTree, suite.fs, msg)
require.NoError(suite.T(), err)
Expand Down
8 changes: 8 additions & 0 deletions internal/testHelpers/testHelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package testHelpers

import (
"fmt"
"github.com/go-git/go-git/v5/plumbing"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -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),
})
}

0 comments on commit f7e4ae7

Please sign in to comment.