refactor: interface for commit message analyzer

This commit is contained in:
Julian Tölle 2024-08-08 18:29:34 +02:00
parent 8f106e4028
commit 7797a86a48
3 changed files with 24 additions and 25 deletions

View file

@ -3,7 +3,6 @@ package rp
import (
"testing"
"github.com/leodido/go-conventionalcommits"
"github.com/stretchr/testify/assert"
)
@ -12,14 +11,12 @@ func TestAnalyzeCommits(t *testing.T) {
name string
commits []Commit
expectedCommits []AnalyzedCommit
expectedBump conventionalcommits.VersionBump
wantErr assert.ErrorAssertionFunc
}{
{
name: "empty commits",
commits: []Commit{},
expectedCommits: []AnalyzedCommit{},
expectedBump: conventionalcommits.UnknownVersion,
wantErr: assert.NoError,
},
{
@ -30,7 +27,6 @@ func TestAnalyzeCommits(t *testing.T) {
},
},
expectedCommits: nil,
expectedBump: conventionalcommits.UnknownVersion,
wantErr: assert.Error,
},
{
@ -41,7 +37,6 @@ func TestAnalyzeCommits(t *testing.T) {
},
},
expectedCommits: []AnalyzedCommit{},
expectedBump: conventionalcommits.UnknownVersion,
wantErr: assert.NoError,
},
{
@ -61,8 +56,7 @@ func TestAnalyzeCommits(t *testing.T) {
Description: "blabla",
},
},
expectedBump: conventionalcommits.PatchVersion,
wantErr: assert.NoError,
wantErr: assert.NoError,
},
{
name: "highest bump (minor)",
@ -86,8 +80,7 @@ func TestAnalyzeCommits(t *testing.T) {
Description: "foobar",
},
},
expectedBump: conventionalcommits.MinorVersion,
wantErr: assert.NoError,
wantErr: assert.NoError,
},
{
@ -113,19 +106,17 @@ func TestAnalyzeCommits(t *testing.T) {
BreakingChange: true,
},
},
expectedBump: conventionalcommits.MajorVersion,
wantErr: assert.NoError,
wantErr: assert.NoError,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
analyzedCommits, versionBump, err := AnalyzeCommits(tt.commits)
analyzedCommits, err := NewConventionalCommitsParser().AnalyzeCommits(tt.commits)
if !tt.wantErr(t, err) {
return
}
assert.Equal(t, tt.expectedCommits, analyzedCommits)
assert.Equal(t, tt.expectedBump, versionBump)
})
}
}