2020-11-09 09:29:27 +00:00
|
|
|
package convention
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2021-04-15 04:28:04 +00:00
|
|
|
"time"
|
2020-11-09 09:29:27 +00:00
|
|
|
|
|
|
|
"github.com/sebdah/goldie/v2"
|
2020-11-27 09:53:52 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-11-27 18:28:59 +00:00
|
|
|
|
|
|
|
"github.com/haunt98/changeloguru/internal/git"
|
2020-11-09 09:29:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewCommit(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
2020-11-10 08:39:54 +00:00
|
|
|
c git.Commit
|
2020-11-09 09:29:27 +00:00
|
|
|
wantErr error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Commit message with not character to draw attention to breaking change",
|
2020-11-10 08:39:54 +00:00
|
|
|
c: git.Commit{
|
|
|
|
Message: "refactor!: drop support for Node 6",
|
|
|
|
},
|
2020-11-09 09:29:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Commit message with no body",
|
2020-11-10 08:39:54 +00:00
|
|
|
c: git.Commit{
|
|
|
|
Message: "docs: correct spelling of CHANGELOG",
|
|
|
|
},
|
2020-11-09 09:29:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Commit message with scope",
|
2020-11-10 08:39:54 +00:00
|
|
|
c: git.Commit{
|
|
|
|
Message: "feat(lang): add polish language",
|
|
|
|
},
|
2020-11-09 09:29:27 +00:00
|
|
|
},
|
2023-12-25 09:18:24 +00:00
|
|
|
{
|
|
|
|
name: "Commit message with scope",
|
|
|
|
c: git.Commit{
|
|
|
|
Message: "feat(bump00): allow bump minor",
|
|
|
|
},
|
|
|
|
},
|
2020-12-02 08:48:22 +00:00
|
|
|
{
|
|
|
|
name: "Uppercase",
|
|
|
|
c: git.Commit{
|
|
|
|
Message: "REFACTOR!: drop support for Node 6",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Mixedcase",
|
|
|
|
c: git.Commit{
|
|
|
|
Message: "Docs: correct spelling of CHANGELOG",
|
|
|
|
},
|
|
|
|
},
|
2021-01-11 18:27:08 +00:00
|
|
|
{
|
|
|
|
name: "Misc",
|
|
|
|
c: git.Commit{
|
|
|
|
Message: "random git message",
|
|
|
|
},
|
|
|
|
},
|
2021-04-15 04:28:04 +00:00
|
|
|
{
|
|
|
|
name: "Misc with author date",
|
|
|
|
c: git.Commit{
|
|
|
|
Message: "random git message",
|
|
|
|
Author: git.Author{
|
|
|
|
When: time.Date(2020, 4, 1, 0, 0, 0, 0, time.Local),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-05-11 04:57:25 +00:00
|
|
|
{
|
|
|
|
name: "Empty commit",
|
|
|
|
wantErr: ErrEmptyCommit,
|
|
|
|
},
|
2020-11-09 09:29:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tests {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
g := goldie.New(t)
|
|
|
|
|
2020-11-10 08:39:54 +00:00
|
|
|
gotResult, gotErr := NewCommit(tc.c)
|
2020-11-27 09:53:52 +00:00
|
|
|
assert.Equal(t, tc.wantErr, gotErr)
|
2020-11-09 09:29:27 +00:00
|
|
|
if tc.wantErr != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
g.AssertJson(t, t.Name(), gotResult)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|