teat: unit test for new conventional commit
parent
fc465926e3
commit
818cf7d270
2
go.mod
2
go.mod
|
@ -5,6 +5,8 @@ go 1.15
|
|||
require (
|
||||
github.com/go-git/go-git v4.7.0+incompatible
|
||||
github.com/go-git/go-git/v5 v5.2.0
|
||||
github.com/google/go-cmp v0.3.0
|
||||
github.com/sebdah/goldie/v2 v2.5.1
|
||||
github.com/spf13/cobra v1.1.1
|
||||
github.com/urfave/cli/v2 v2.3.0
|
||||
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de // indirect
|
||||
|
|
4
go.sum
4
go.sum
|
@ -116,6 +116,7 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO
|
|||
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
|
||||
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
||||
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
||||
github.com/haunt98/converter v0.0.0-20201106100128-c3708e9bab33 h1:u6Tya29fCvhMiedEMiR4rbX+D+6SUzgL9EasB5wOflY=
|
||||
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
|
||||
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
|
@ -183,6 +184,9 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0
|
|||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||
github.com/sebdah/goldie v1.0.0 h1:9GNhIat69MSlz/ndaBg48vl9dF5fI+NBB6kfOxgfkMc=
|
||||
github.com/sebdah/goldie/v2 v2.5.1 h1:hh70HvG4n3T3MNRJN2z/baxPR8xutxo7JVxyi2svl+s=
|
||||
github.com/sebdah/goldie/v2 v2.5.1/go.mod h1:oZ9fp0+se1eapSRjfYbsV/0Hqhbuu3bJVvKI/NNtssI=
|
||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
||||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
||||
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package comparision
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
func Diff(t *testing.T, want, got interface{}) {
|
||||
if diff := cmp.Diff(want, got); diff != "" {
|
||||
t.Errorf("mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
}
|
|
@ -25,7 +25,8 @@ type Commit struct {
|
|||
}
|
||||
|
||||
func NewCommit(c git.Commit) (result Commit, err error) {
|
||||
messages := strings.Split(c.Message, "\n")
|
||||
message := strings.TrimSpace(c.Message)
|
||||
messages := strings.Split(message, "\n")
|
||||
if len(messages) == 0 {
|
||||
err = errors.New("empty commit")
|
||||
return
|
||||
|
@ -36,7 +37,7 @@ func NewCommit(c git.Commit) (result Commit, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
bodyAndFooters := c.Message[len(header):]
|
||||
bodyAndFooters := message[len(header):]
|
||||
parseBodyAndFooters(bodyAndFooters, &result)
|
||||
|
||||
return
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package convention
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/haunt98/changeloguru/pkg/comparision"
|
||||
"github.com/haunt98/changeloguru/pkg/git"
|
||||
"github.com/sebdah/goldie/v2"
|
||||
)
|
||||
|
||||
func TestNewCommit(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
wantErr error
|
||||
}{
|
||||
{
|
||||
name: "Commit message with description and breaking change footer",
|
||||
},
|
||||
{
|
||||
name: "Commit message with not character to draw attention to breaking change",
|
||||
},
|
||||
{
|
||||
name: "Commit message with no body",
|
||||
},
|
||||
{
|
||||
name: "Commit message with scope",
|
||||
},
|
||||
{
|
||||
name: "Commit message with multi-paragraph body and multiple footers",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
g := goldie.New(t)
|
||||
gName := g.GoldenFileName(t, t.Name())
|
||||
|
||||
inputName := strings.TrimSuffix(gName, ".golden") + ".txt"
|
||||
fmt.Println("inputName", inputName)
|
||||
bytes, err := ioutil.ReadFile(inputName)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
gotResult, gotErr := NewCommit(git.Commit{
|
||||
Message: string(bytes),
|
||||
})
|
||||
comparision.Diff(t, tc.wantErr, gotErr)
|
||||
if tc.wantErr != nil {
|
||||
return
|
||||
}
|
||||
g.AssertJson(t, t.Name(), gotResult)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"Type": "feat",
|
||||
"Scope": "",
|
||||
"Description": "allow provided config object to extend other configs",
|
||||
"BodyAndFooters": "BREAKING CHANGE: `extends` key in config file is now used for extending other config files"
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
feat: allow provided config object to extend other configs
|
||||
|
||||
BREAKING CHANGE: `extends` key in config file is now used for extending other config files
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"Type": "fix",
|
||||
"Scope": "",
|
||||
"Description": "correct minor typos in code",
|
||||
"BodyAndFooters": "see the issue for details\n\non typos fixed.\n\nReviewed-by: Z\nRefs #133"
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fix: correct minor typos in code
|
||||
|
||||
see the issue for details
|
||||
|
||||
on typos fixed.
|
||||
|
||||
Reviewed-by: Z
|
||||
Refs #133
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"Type": "docs",
|
||||
"Scope": "",
|
||||
"Description": "correct spelling of CHANGELOG",
|
||||
"BodyAndFooters": ""
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
docs: correct spelling of CHANGELOG
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"Type": "refactor",
|
||||
"Scope": "",
|
||||
"Description": "drop support for Node 6",
|
||||
"BodyAndFooters": ""
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
refactor!: drop support for Node 6
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"Type": "feat",
|
||||
"Scope": "lang",
|
||||
"Description": "add polish language",
|
||||
"BodyAndFooters": ""
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
feat(lang): add polish language
|
Loading…
Reference in New Issue