-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathconventional_commits_test.go
116 lines (99 loc) · 2.02 KB
/
conventional_commits_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetTypeKeyword(t *testing.T) {
tests := map[string]struct {
body string
expected string
}{
"fix": {
"mark-pr as fix",
"fix",
},
"feat": {
"mark-pr as feat",
"feat",
},
"with test-bot prefix": {
`@mender-test-bot
mark-pr as feat`,
"feat",
},
"with test-bot prefix single-line": {
"@mender-test-bot mark-pr as feat",
"feat",
},
"with test-bot prefix and space chars at the end": {
"@mender-test-bot mark-pr as feat\n\t\r ",
"feat",
},
"with colon": {
"mark-pr as: feat",
"feat",
},
}
testErrors := map[string]string{
"illegal": "mark-pr as illegal",
"without propper conventional commit command": `@mender-tets-bot
mark pr as feat`,
}
for name, test := range tests {
t.Log(name)
res, _ := getTypeKeyword(test.body)
assert.Equal(t, test.expected, res)
}
for name := range testErrors {
t.Log(name)
_, err := getTypeKeyword(testErrors[name])
assert.True(t, err != nil)
}
}
func TestConventionalComittifyDependabotMessage(t *testing.T) {
tests := map[string]struct {
typeKeyword string
body string
expected string
}{
"commit message with sign-off in footer": {
"feat",
`feature description
body
Signed-off-by: dependabot[bot]`,
`feat: feature description
body
Changelog: All
Ticket: None
Signed-off-by: dependabot[bot]`,
},
"with changelog prefix and newline at the end": {
"feat",
`Changelog:All: feature description
body
Signed-off-by: dependabot[bot]
`,
`feat: feature description
body
Changelog: All
Ticket: None
Signed-off-by: dependabot[bot]`,
},
"with changelog chore prefix": {
"feat",
`chore: feature description
body
Signed-off-by: dependabot[bot]`,
`feat: feature description
body
Changelog: All
Ticket: None
Signed-off-by: dependabot[bot]`,
},
}
for name, test := range tests {
t.Log(name)
res := conventionalComittifyDependabotMessage(test.body, test.typeKeyword)
assert.Equal(t, test.expected, res)
}
}