test(changelog): unit test for changelog with markdown
parent
694261892c
commit
98eb8cc928
|
@ -112,7 +112,7 @@ func (g *MarkdownGenerator) getOldNodes() []markdown.Node {
|
|||
|
||||
result = append(result, markdown.Parse(lines)...)
|
||||
|
||||
// remove title
|
||||
// remove title as we will add later
|
||||
if len(result) > 0 && markdown.Equal(result[0], markdown.NewHeader(firstLevel, title)) {
|
||||
result = result[1:]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package changelog
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/haunt98/changeloguru/pkg/convention"
|
||||
"github.com/sebdah/goldie/v2"
|
||||
)
|
||||
|
||||
func TestMarkdownGeneratorGenerate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
oldData string
|
||||
version string
|
||||
t time.Time
|
||||
commits []convention.Commit
|
||||
}{
|
||||
{
|
||||
name: "empty old data",
|
||||
version: "v1.0.0",
|
||||
t: time.Date(2020, 1, 18, 0, 0, 0, 0, time.Local),
|
||||
commits: []convention.Commit{
|
||||
{
|
||||
RawHeader: "feat: new feature",
|
||||
Type: convention.FeatType,
|
||||
},
|
||||
{
|
||||
RawHeader: "fix: new fix",
|
||||
Type: convention.FixType,
|
||||
},
|
||||
{
|
||||
RawHeader: "chore: new build",
|
||||
Type: convention.ChoreType,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
g := goldie.New(t)
|
||||
markdownGenerator := NewMarkdownGenerator(tc.oldData, tc.version, tc.t)
|
||||
got := markdownGenerator.Generate(tc.commits)
|
||||
g.Assert(t, t.Name(), []byte(got))
|
||||
})
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
# CHANGELOG
|
||||
|
||||
## v1.0.0 (2020-1-18)
|
||||
|
||||
### Added
|
||||
|
||||
- feat: new feature
|
||||
|
||||
### Fixed
|
||||
|
||||
- feat: new feature
|
||||
|
||||
### Others
|
||||
|
||||
- chore: new build
|
|
@ -10,6 +10,8 @@ func Parse(lines []string) []Node {
|
|||
bases := make([]Node, 0, defaultBaseLen)
|
||||
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
|
||||
if line == "" {
|
||||
continue
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue