test: unit test for filter commits with scope

main
sudo pacman -Syu 2021-06-16 18:11:32 +00:00
parent bc4b6e45e1
commit dfe5a5a506
1 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,100 @@
package changelog
import (
"testing"
"github.com/haunt98/changeloguru/internal/convention"
"github.com/stretchr/testify/assert"
)
func TestFilter(t *testing.T) {
tests := []struct {
name string
commits []convention.Commit
scopes map[string]struct{}
want map[string][]convention.Commit
}{
{
name: "without scopes",
commits: []convention.Commit{
{
RawHeader: "feature A",
Type: convention.FeatType,
},
{
RawHeader: "fix B",
Type: convention.FixType,
},
{
RawHeader: "build",
Type: convention.BuildType,
},
},
want: map[string][]convention.Commit{
addedType: {
{
RawHeader: "feature A",
Type: convention.FeatType,
},
},
fixedType: {
{
RawHeader: "fix B",
Type: convention.FixType,
},
},
othersType: {
{
RawHeader: "build",
Type: convention.BuildType,
},
},
},
},
{
name: "with scopes",
commits: []convention.Commit{
{
RawHeader: "feature A",
Type: convention.FeatType,
Scope: "A",
},
{
RawHeader: "fix B",
Type: convention.FixType,
Scope: "B",
},
{
RawHeader: "build",
Type: convention.BuildType,
},
},
scopes: map[string]struct{}{
"A": {},
},
want: map[string][]convention.Commit{
addedType: {
{
RawHeader: "feature A",
Type: convention.FeatType,
Scope: "A",
},
},
fixedType: {},
othersType: {
{
RawHeader: "build",
Type: convention.BuildType,
},
},
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got := filter(tc.commits, tc.scopes)
assert.Equal(t, tc.want, got)
})
}
}