Skip to content

Commit 93d1671

Browse files
authored
feat(test): add more unit tests (#30)
1 parent 3c672a0 commit 93d1671

File tree

6 files changed

+146
-14
lines changed

6 files changed

+146
-14
lines changed

go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/charmbracelet/bubbles v0.18.0
77
github.com/charmbracelet/bubbletea v0.25.0
88
github.com/charmbracelet/lipgloss v0.10.0
9+
github.com/onsi/gomega v1.31.1
910
github.com/shipengqi/component-base v0.2.4
1011
github.com/shipengqi/golib v0.2.11
1112
github.com/spf13/cobra v1.8.0
@@ -18,6 +19,7 @@ require (
1819
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
1920
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
2021
github.com/fatih/color v1.16.0 // indirect
22+
github.com/google/go-cmp v0.6.0 // indirect
2123
github.com/gosuri/uitable v0.0.4 // indirect
2224
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2325
github.com/kr/text v0.2.0 // indirect
@@ -32,8 +34,9 @@ require (
3234
github.com/muesli/termenv v0.15.2 // indirect
3335
github.com/rivo/uniseg v0.4.7 // indirect
3436
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f // indirect
37+
golang.org/x/net v0.19.0 // indirect
3538
golang.org/x/sync v0.1.0 // indirect
3639
golang.org/x/sys v0.18.0 // indirect
37-
golang.org/x/term v0.6.0 // indirect
38-
golang.org/x/text v0.4.0 // indirect
40+
golang.org/x/term v0.15.0 // indirect
41+
golang.org/x/text v0.14.0 // indirect
3942
)

go.sum

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
1616
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1717
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
1818
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
19+
github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY=
20+
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
21+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
22+
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls=
23+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
24+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
25+
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
26+
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
1927
github.com/gosuri/uitable v0.0.4 h1:IG2xLKRvErL3uhY6e1BylFzG+aJiwQviDDTfOKeKTpY=
2028
github.com/gosuri/uitable v0.0.4/go.mod h1:tKR86bXuXPZazfOTG1FIzvjIdXzd0mo4Vtn16vt0PJo=
2129
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
@@ -46,6 +54,10 @@ github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
4654
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
4755
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
4856
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
57+
github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY=
58+
github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM=
59+
github.com/onsi/gomega v1.31.1 h1:KYppCUK+bUgAZwHOu7EXVBKyQA6ILvOESHkn/tgoqvo=
60+
github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0=
4961
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5062
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5163
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
@@ -65,17 +77,21 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
6577
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
6678
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
6779
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
80+
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
81+
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
6882
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
6983
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
7084
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7185
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7286
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7387
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
7488
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
75-
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
76-
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
77-
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
78-
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
89+
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
90+
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
91+
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
92+
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
93+
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
94+
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
7995
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
8096
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
8197
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

internal/config/config_test.go

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,41 @@
1-
package config
1+
package config_test
22

3-
import "testing"
3+
import (
4+
"testing"
5+
6+
. "github.com/onsi/gomega"
7+
8+
"github.com/shipengqi/commitizen/internal/config"
9+
)
410

511
func TestLoadTemplates(t *testing.T) {
6-
ts, err := LoadTemplates("./testdata/.git-czrc")
7-
if err != nil {
8-
t.Log(err)
12+
tests := []struct {
13+
title string
14+
tmpl string
15+
expect int
16+
}{
17+
{
18+
"without any default templates",
19+
"./testdata/.git-czrc",
20+
2,
21+
},
22+
{
23+
"with one default templates",
24+
"./testdata/.git-czrc-with-default",
25+
2,
26+
},
27+
{
28+
"with two default templates",
29+
"./testdata/.git-czrc-with-two-default",
30+
2,
31+
},
32+
}
33+
g := NewWithT(t)
34+
for _, v := range tests {
35+
t.Run(v.title, func(t *testing.T) {
36+
ts, err := config.LoadTemplates(v.tmpl)
37+
g.Expect(err).To(BeNil())
38+
g.Expect(len(ts)).To(Equal(v.expect))
39+
})
940
}
10-
t.Log(ts)
1141
}

internal/config/testdata/.git-czrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ format: "{{.type}}{{with .scope}}({{.}}){{end}}: {{.subject}}{{with .body}}\n\n{
4242
---
4343

4444
name: ot
45-
default: true
4645
items:
4746
- name: type
4847
desc: "Select the type of change that you're committing:"

internal/config/testdata/.git-czrc-with-default

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name: mf
2-
default: true
32
items:
43
- name: type
54
desc: "Select the type of change that you're committing:"
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: mf
2+
default: true
3+
items:
4+
- name: type
5+
desc: "Select the type of change that you're committing:"
6+
type: select
7+
options:
8+
- name: feat
9+
desc: "A new feature"
10+
- name: fix
11+
desc: "A bug fix"
12+
- name: docs
13+
desc: "Documentation only changes"
14+
- name: test
15+
desc: "Adding missing tests"
16+
- name: WIP
17+
desc: "Work in progress"
18+
- name: chore
19+
desc: "Changes to the build process or auxiliary tools\n and libraries such as documentation generation"
20+
- name: style
21+
desc: "Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)"
22+
- name: refactor
23+
desc: "A code change that neither fixes a bug nor adds a feature"
24+
- name: perf
25+
desc: "A code change that improves performance"
26+
- name: revert
27+
desc: "Revert to a commit"
28+
- name: scope
29+
desc: "Scope. Could be anything specifying place of the commit change:"
30+
type: input
31+
- name: subject
32+
desc: "Subject. Concise description of the changes. Imperative, lower case and no final dot:"
33+
type: input
34+
required: true
35+
- name: body
36+
desc: "Body. Motivation for the change and contrast this with previous behavior:"
37+
type: textarea
38+
- name: footer
39+
desc: "Footer. Information about Breaking Changes and reference issues that this commit closes:"
40+
type: textarea
41+
format: "{{.type}}{{with .scope}}({{.}}){{end}}: {{.subject}}{{with .body}}\n\n{{.}}{{end}}{{with .footer}}\n\n{{.}}{{end}}"
42+
43+
---
44+
45+
name: ot
46+
default: true
47+
items:
48+
- name: type
49+
desc: "Select the type of change that you're committing:"
50+
type: select
51+
options:
52+
- name: feat
53+
desc: "A new feature"
54+
- name: fix
55+
desc: "A bug fix"
56+
- name: docs
57+
desc: "Documentation only changes"
58+
- name: test
59+
desc: "Adding missing tests"
60+
- name: WIP
61+
desc: "Work in progress"
62+
- name: chore
63+
desc: "Changes to the build process or auxiliary tools\n and libraries such as documentation generation"
64+
- name: style
65+
desc: "Changes that do not affect the meaning of the code\n (white-space, formatting, missing semi-colons, etc)"
66+
- name: refactor
67+
desc: "A code change that neither fixes a bug nor adds a feature"
68+
- name: perf
69+
desc: "A code change that improves performance"
70+
- name: revert
71+
desc: "Revert to a commit"
72+
- name: scope
73+
desc: "Scope. Could be anything specifying place of the commit change:"
74+
type: input
75+
- name: subject
76+
desc: "Subject. Concise description of the changes. Imperative, lower case and no final dot:"
77+
type: input
78+
required: true
79+
- name: body
80+
desc: "Body. Motivation for the change and contrast this with previous behavior:"
81+
type: textarea
82+
- name: footer
83+
desc: "Footer. Information about Breaking Changes and reference issues that this commit closes:"
84+
type: textarea
85+
format: "{{.type}}{{with .scope}}({{.}}){{end}}: {{.subject}}{{with .body}}\n\n{{.}}{{end}}{{with .footer}}\n\n{{.}}{{end}}"

0 commit comments

Comments
 (0)