2020-05-01 03:45:08 +00:00
|
|
|
package sv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-02-13 18:40:09 +00:00
|
|
|
"github.com/Masterminds/semver/v3"
|
2020-05-01 03:45:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var dateChangelog = `## v1.0.0 (2020-05-01)
|
|
|
|
`
|
|
|
|
var emptyDateChangelog = `## v1.0.0
|
|
|
|
`
|
2021-01-25 20:16:56 +00:00
|
|
|
var emptyVersionChangelog = `## 2020-05-01
|
|
|
|
`
|
2021-07-31 00:03:34 +00:00
|
|
|
var fullChangeLog = `## v1.0.0 (2020-05-01)
|
|
|
|
|
|
|
|
### Features
|
|
|
|
|
|
|
|
- subject text ()
|
|
|
|
|
|
|
|
### Bug Fixes
|
|
|
|
|
|
|
|
- subject text ()
|
|
|
|
|
|
|
|
### Build
|
|
|
|
|
|
|
|
- subject text ()
|
|
|
|
|
|
|
|
### Breaking Changes
|
|
|
|
|
|
|
|
- break change message
|
|
|
|
`
|
2020-05-01 03:45:08 +00:00
|
|
|
|
|
|
|
func TestOutputFormatterImpl_FormatReleaseNote(t *testing.T) {
|
|
|
|
date, _ := time.Parse("2006-01-02", "2020-05-01")
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
input ReleaseNote
|
|
|
|
want string
|
|
|
|
}{
|
2021-01-25 20:16:56 +00:00
|
|
|
{"with date", emptyReleaseNote("1.0.0", date.Truncate(time.Minute)), dateChangelog},
|
|
|
|
{"without date", emptyReleaseNote("1.0.0", time.Time{}.Truncate(time.Minute)), emptyDateChangelog},
|
|
|
|
{"without version", emptyReleaseNote("", date.Truncate(time.Minute)), emptyVersionChangelog},
|
2021-07-31 00:03:34 +00:00
|
|
|
{"full changelog", fullReleaseNote("1.0.0", date.Truncate(time.Minute)), fullChangeLog},
|
2020-05-01 03:45:08 +00:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if got := NewOutputFormatter().FormatReleaseNote(tt.input); got != tt.want {
|
|
|
|
t.Errorf("OutputFormatterImpl.FormatReleaseNote() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func emptyReleaseNote(version string, date time.Time) ReleaseNote {
|
2021-01-25 20:16:56 +00:00
|
|
|
var v *semver.Version
|
|
|
|
if version != "" {
|
|
|
|
v = semver.MustParse(version)
|
|
|
|
}
|
2020-05-01 03:45:08 +00:00
|
|
|
return ReleaseNote{
|
2021-01-25 20:16:56 +00:00
|
|
|
Version: v,
|
2020-05-01 03:45:08 +00:00
|
|
|
Date: date,
|
|
|
|
}
|
|
|
|
}
|
2021-07-31 00:03:34 +00:00
|
|
|
|
|
|
|
func fullReleaseNote(version string, date time.Time) ReleaseNote {
|
|
|
|
var v *semver.Version
|
|
|
|
if version != "" {
|
|
|
|
v = semver.MustParse(version)
|
|
|
|
}
|
|
|
|
|
|
|
|
sections := map[string]ReleaseNoteSection{
|
|
|
|
"build": newReleaseNoteSection("Build", []GitCommitLog{commitlog("build", map[string]string{})}),
|
|
|
|
"feat": newReleaseNoteSection("Features", []GitCommitLog{commitlog("feat", map[string]string{})}),
|
|
|
|
"fix": newReleaseNoteSection("Bug Fixes", []GitCommitLog{commitlog("fix", map[string]string{})}),
|
|
|
|
}
|
|
|
|
return releaseNote(v, date, sections, []string{"break change message"})
|
|
|
|
}
|