0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-24 21:20:40 +00:00
git-sv/sv/releasenotes_test.go
2020-02-01 23:51:29 -03:00

52 lines
1.8 KiB
Go

package sv
import (
"reflect"
"testing"
"time"
"github.com/Masterminds/semver"
)
func TestReleaseNoteProcessorImpl_Create(t *testing.T) {
date := time.Now()
tests := []struct {
name string
version semver.Version
date time.Time
commits []GitCommitLog
want ReleaseNote
}{
{
name: "mapped tag",
version: *semver.MustParse("1.0.0"),
date: date,
commits: []GitCommitLog{commitlog("t1", map[string]string{})},
want: releaseNote(*semver.MustParse("1.0.0"), date, map[string]ReleaseNoteSection{"t1": newReleaseNoteSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, nil),
},
{
name: "unmapped tag",
version: *semver.MustParse("1.0.0"),
date: date,
commits: []GitCommitLog{commitlog("t1", map[string]string{}), commitlog("unmapped", map[string]string{})},
want: releaseNote(*semver.MustParse("1.0.0"), date, map[string]ReleaseNoteSection{"t1": newReleaseNoteSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, nil),
},
{
name: "breaking changes tag",
version: *semver.MustParse("1.0.0"),
date: date,
commits: []GitCommitLog{commitlog("t1", map[string]string{}), commitlog("unmapped", map[string]string{"breakingchange": "breaks"})},
want: releaseNote(*semver.MustParse("1.0.0"), date, map[string]ReleaseNoteSection{"t1": newReleaseNoteSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, []string{"breaks"}),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := NewReleaseNoteProcessor(map[string]string{"t1": "Tag 1", "t2": "Tag 2"})
if got := p.Create(tt.version, tt.date, tt.commits); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ReleaseNoteProcessorImpl.Create() = %v, want %v", got, tt.want)
}
})
}
}