0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-11-12 15:00:39 +00:00

test: unit tests for releasenotes.go

This commit is contained in:
Beatriz Vieira 2019-11-17 14:43:01 -03:00
parent ad7a5286b9
commit 729cfb5f49
3 changed files with 73 additions and 14 deletions

35
sv/helpers_test.go Normal file
View File

@ -0,0 +1,35 @@
package sv
import (
"time"
"github.com/Masterminds/semver"
)
func version(v string) semver.Version {
r, _ := semver.NewVersion(v)
return *r
}
func commitlog(t string, metadata map[string]string) GitCommitLog {
return GitCommitLog{
Type: t,
Subject: "subject text",
Metadata: metadata,
}
}
func releaseNote(sections map[string]ReleaseNoteSection, breakingChanges []string) ReleaseNote {
return ReleaseNote{
Date: time.Now().Truncate(time.Minute),
Sections: sections,
BreakingChanges: breakingChanges,
}
}
func rnSection(name string, items []GitCommitLog) ReleaseNoteSection {
return ReleaseNoteSection{
Name: name,
Items: items,
}
}

38
sv/releasenotes_test.go Normal file
View File

@ -0,0 +1,38 @@
package sv
import (
"reflect"
"testing"
)
func TestReleaseNoteProcessorImpl_Get(t *testing.T) {
tests := []struct {
name string
commits []GitCommitLog
want ReleaseNote
}{
{
name: "mapped tag",
commits: []GitCommitLog{commitlog("t1", map[string]string{})},
want: releaseNote(map[string]ReleaseNoteSection{"t1": rnSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, nil),
},
{
name: "unmapped tag",
commits: []GitCommitLog{commitlog("t1", map[string]string{}), commitlog("unmapped", map[string]string{})},
want: releaseNote(map[string]ReleaseNoteSection{"t1": rnSection("Tag 1", []GitCommitLog{commitlog("t1", map[string]string{})})}, nil),
},
{
name: "breaking changes tag",
commits: []GitCommitLog{commitlog("t1", map[string]string{}), commitlog("unmapped", map[string]string{"breakingchange": "breaks"})},
want: releaseNote(map[string]ReleaseNoteSection{"t1": rnSection("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.Get(tt.commits); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ReleaseNoteProcessorImpl.Get() = %v, want %v", got, tt.want)
}
})
}
}

View File

@ -57,17 +57,3 @@ func TestToVersion(t *testing.T) {
})
}
}
// helpers
func version(v string) semver.Version {
r, _ := semver.NewVersion(v)
return *r
}
func commitlog(t string, metadata map[string]string) GitCommitLog {
return GitCommitLog{
Type: t,
Metadata: metadata,
}
}