2019-11-17 17:43:01 +00:00
|
|
|
package sv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
2020-02-01 21:19:38 +00:00
|
|
|
"time"
|
2020-02-02 00:00:53 +00:00
|
|
|
|
2021-02-13 18:40:09 +00:00
|
|
|
"github.com/Masterminds/semver/v3"
|
2019-11-17 17:43:01 +00:00
|
|
|
)
|
|
|
|
|
2020-02-02 00:00:53 +00:00
|
|
|
func TestReleaseNoteProcessorImpl_Create(t *testing.T) {
|
2020-02-01 21:19:38 +00:00
|
|
|
date := time.Now()
|
|
|
|
|
2019-11-17 17:43:01 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
2021-01-25 20:16:56 +00:00
|
|
|
version *semver.Version
|
2020-02-01 21:19:38 +00:00
|
|
|
date time.Time
|
2019-11-17 17:43:01 +00:00
|
|
|
commits []GitCommitLog
|
|
|
|
want ReleaseNote
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "mapped tag",
|
2021-01-25 20:16:56 +00:00
|
|
|
version: semver.MustParse("1.0.0"),
|
2020-02-01 21:19:38 +00:00
|
|
|
date: date,
|
2019-11-17 17:43:01 +00:00
|
|
|
commits: []GitCommitLog{commitlog("t1", map[string]string{})},
|
2021-01-25 20:16:56 +00:00
|
|
|
want: releaseNote(semver.MustParse("1.0.0"), date, map[string]ReleaseNoteSection{"t1": newReleaseNoteSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, nil),
|
2019-11-17 17:43:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "unmapped tag",
|
2021-01-25 20:16:56 +00:00
|
|
|
version: semver.MustParse("1.0.0"),
|
2020-02-01 21:19:38 +00:00
|
|
|
date: date,
|
2019-11-17 17:43:01 +00:00
|
|
|
commits: []GitCommitLog{commitlog("t1", map[string]string{}), commitlog("unmapped", map[string]string{})},
|
2021-01-25 20:16:56 +00:00
|
|
|
want: releaseNote(semver.MustParse("1.0.0"), date, map[string]ReleaseNoteSection{"t1": newReleaseNoteSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, nil),
|
2019-11-17 17:43:01 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "breaking changes tag",
|
2021-01-25 20:16:56 +00:00
|
|
|
version: semver.MustParse("1.0.0"),
|
2020-02-01 21:19:38 +00:00
|
|
|
date: date,
|
2021-02-14 02:35:31 +00:00
|
|
|
commits: []GitCommitLog{commitlog("t1", map[string]string{}), commitlog("unmapped", map[string]string{"breaking-change": "breaks"})},
|
2021-01-25 20:16:56 +00:00
|
|
|
want: releaseNote(semver.MustParse("1.0.0"), date, map[string]ReleaseNoteSection{"t1": newReleaseNoteSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, []string{"breaks"}),
|
2019-11-17 17:43:01 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
p := NewReleaseNoteProcessor(map[string]string{"t1": "Tag 1", "t2": "Tag 2"})
|
2020-02-02 00:00:53 +00:00
|
|
|
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)
|
2019-11-17 17:43:01 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|