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
|
|
|
)
|
|
|
|
|
2023-10-15 19:29:29 +00:00
|
|
|
func TestBaseReleaseNoteProcessor_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
|
2021-12-29 21:02:50 +00:00
|
|
|
tag string
|
2020-02-01 21:19:38 +00:00
|
|
|
date time.Time
|
2023-10-15 19:29:29 +00:00
|
|
|
commits []CommitLog
|
2019-11-17 17:43:01 +00:00
|
|
|
want ReleaseNote
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "mapped tag",
|
2021-01-25 20:16:56 +00:00
|
|
|
version: semver.MustParse("1.0.0"),
|
2021-12-29 21:02:50 +00:00
|
|
|
tag: "v1.0.0",
|
2020-02-01 21:19:38 +00:00
|
|
|
date: date,
|
2023-10-15 19:29:29 +00:00
|
|
|
commits: []CommitLog{TestCommitlog("t1", map[string]string{}, "a")},
|
|
|
|
want: TestReleaseNote(
|
2023-10-12 14:18:25 +00:00
|
|
|
semver.MustParse("1.0.0"),
|
|
|
|
"v1.0.0",
|
|
|
|
date,
|
|
|
|
[]ReleaseNoteSection{
|
2023-10-15 19:29:29 +00:00
|
|
|
TestNewReleaseNoteCommitsSection(
|
|
|
|
"Tag 1", []string{"t1"}, []CommitLog{TestCommitlog("t1", map[string]string{}, "a")},
|
|
|
|
),
|
2023-10-12 14:18:25 +00:00
|
|
|
},
|
|
|
|
map[string]struct{}{"a": {}},
|
|
|
|
),
|
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"),
|
2021-12-29 21:02:50 +00:00
|
|
|
tag: "v1.0.0",
|
2020-02-01 21:19:38 +00:00
|
|
|
date: date,
|
2023-10-15 19:29:29 +00:00
|
|
|
commits: []CommitLog{
|
|
|
|
TestCommitlog("t1", map[string]string{}, "a"), TestCommitlog("unmapped", map[string]string{}, "a"),
|
|
|
|
},
|
|
|
|
want: TestReleaseNote(
|
2023-10-12 14:18:25 +00:00
|
|
|
semver.MustParse("1.0.0"),
|
|
|
|
"v1.0.0",
|
|
|
|
date,
|
|
|
|
[]ReleaseNoteSection{
|
2023-10-15 19:29:29 +00:00
|
|
|
TestNewReleaseNoteCommitsSection(
|
|
|
|
"Tag 1", []string{"t1"}, []CommitLog{TestCommitlog("t1", map[string]string{}, "a")},
|
|
|
|
),
|
2023-10-12 14:18:25 +00:00
|
|
|
},
|
|
|
|
map[string]struct{}{"a": {}},
|
|
|
|
),
|
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"),
|
2021-12-29 21:02:50 +00:00
|
|
|
tag: "v1.0.0",
|
2020-02-01 21:19:38 +00:00
|
|
|
date: date,
|
2023-10-15 19:29:29 +00:00
|
|
|
commits: []CommitLog{
|
|
|
|
TestCommitlog("t1", map[string]string{}, "a"),
|
|
|
|
TestCommitlog("unmapped", map[string]string{"breaking-change": "breaks"}, "a"),
|
2023-10-12 14:18:25 +00:00
|
|
|
},
|
2023-10-15 19:29:29 +00:00
|
|
|
want: TestReleaseNote(
|
2023-10-12 14:18:25 +00:00
|
|
|
semver.MustParse("1.0.0"),
|
|
|
|
"v1.0.0",
|
|
|
|
date,
|
|
|
|
[]ReleaseNoteSection{
|
2023-10-15 19:29:29 +00:00
|
|
|
TestNewReleaseNoteCommitsSection(
|
|
|
|
"Tag 1", []string{"t1"}, []CommitLog{TestCommitlog("t1", map[string]string{}, "a")},
|
|
|
|
),
|
2023-10-12 14:18:25 +00:00
|
|
|
ReleaseNoteBreakingChangeSection{Name: "Breaking Changes", Messages: []string{"breaks"}},
|
|
|
|
},
|
|
|
|
map[string]struct{}{"a": {}},
|
|
|
|
),
|
2022-02-07 01:06:46 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "multiple authors",
|
|
|
|
version: semver.MustParse("1.0.0"),
|
|
|
|
tag: "v1.0.0",
|
|
|
|
date: date,
|
2023-10-15 19:29:29 +00:00
|
|
|
commits: []CommitLog{
|
|
|
|
TestCommitlog("t1", map[string]string{}, "author3"),
|
|
|
|
TestCommitlog("t1", map[string]string{}, "author2"),
|
|
|
|
TestCommitlog("t1", map[string]string{}, "author1"),
|
2023-10-12 14:18:25 +00:00
|
|
|
},
|
2023-10-15 19:29:29 +00:00
|
|
|
want: TestReleaseNote(
|
2023-10-12 14:18:25 +00:00
|
|
|
semver.MustParse("1.0.0"),
|
|
|
|
"v1.0.0",
|
|
|
|
date,
|
|
|
|
[]ReleaseNoteSection{
|
2023-10-15 19:29:29 +00:00
|
|
|
TestNewReleaseNoteCommitsSection("Tag 1", []string{"t1"}, []CommitLog{
|
|
|
|
TestCommitlog("t1", map[string]string{}, "author3"),
|
|
|
|
TestCommitlog("t1", map[string]string{}, "author2"),
|
|
|
|
TestCommitlog("t1", map[string]string{}, "author1"),
|
2023-10-12 14:18:25 +00:00
|
|
|
}),
|
|
|
|
},
|
|
|
|
map[string]struct{}{"author1": {}, "author2": {}, "author3": {}},
|
|
|
|
),
|
2019-11-17 17:43:01 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2023-10-12 14:18:25 +00:00
|
|
|
p := NewReleaseNoteProcessor(
|
|
|
|
ReleaseNotesConfig{
|
|
|
|
Sections: []ReleaseNotesSectionConfig{
|
|
|
|
{Name: "Tag 1", SectionType: "commits", CommitTypes: []string{"t1"}},
|
|
|
|
{Name: "Tag 2", SectionType: "commits", CommitTypes: []string{"t2"}},
|
|
|
|
{Name: "Breaking Changes", SectionType: "breaking-changes"},
|
|
|
|
},
|
|
|
|
})
|
2021-12-29 21:02:50 +00:00
|
|
|
if got := p.Create(tt.version, tt.tag, tt.date, tt.commits); !reflect.DeepEqual(got, tt.want) {
|
2023-10-15 19:29:29 +00:00
|
|
|
t.Errorf("BaseReleaseNoteProcessor.Create() = %v, want %v", got, tt.want)
|
2019-11-17 17:43:01 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|