-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathroot_test.go
180 lines (160 loc) · 4.22 KB
/
root_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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package bump_test
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
bump "github.com/johnmanjiro13/gh-bump"
)
type mockBumper struct {
repository string
isDraft bool
isPrerelease bool
discussionCategory string
generateNotes bool
notes string
notesFilename string
target string
title string
assetFiles []string
bumpType bump.BumpType
yes bool
}
func (b *mockBumper) Bump() error {
return nil
}
func (b *mockBumper) WithRepository(repository string) error {
b.repository = repository
return nil
}
func (b *mockBumper) WithDraft() {
b.isDraft = true
}
func (b *mockBumper) WithPrerelease() {
b.isPrerelease = true
}
func (b *mockBumper) WithDiscussionCategory(category string) {
b.discussionCategory = category
}
func (b *mockBumper) WithGenerateNotes() {
b.generateNotes = true
}
func (b *mockBumper) WithNotes(notes string) {
b.notes = notes
}
func (b *mockBumper) WithNotesFile(filename string) {
b.notesFilename = filename
}
func (b *mockBumper) WithTitle(title string) {
b.title = title
}
func (b *mockBumper) WithTarget(target string) {
b.target = target
}
func (b *mockBumper) WithAssetFiles(files []string) {
b.assetFiles = files
}
func (b *mockBumper) WithBumpType(s string) error {
bumpType, err := bump.ParseBumpType(s)
if err != nil {
return err
}
b.bumpType = bumpType
return nil
}
func (b *mockBumper) WithYes() {
b.yes = true
}
func TestNew(t *testing.T) {
tests := map[string]struct {
command string
wantRepo string
wantDraft bool
wantPrerelease bool
wantDiscussionCategory string
wantGenerateNotes bool
wantNotes string
wantNotesFilename string
wantTarget string
wantTitle string
wantAssetFiles []string
wantBumpType bump.BumpType
wantYes bool
}{
"repository given": {
command: "bump -R johnmanjiro13/gh-bump",
wantRepo: "johnmanjiro13/gh-bump",
},
"current repository": {
command: "bump",
wantRepo: "",
},
"with draft": {
command: "bump --draft",
wantDraft: true,
},
"with prerelease": {
command: "bump --prerelease",
wantPrerelease: true,
},
"with discussion category": {
command: "bump --discussion-category category!",
wantDiscussionCategory: "category!",
},
"with generate-notes": {
command: "bump --generate-notes",
wantGenerateNotes: true,
},
"with notes": {
command: "bump --notes release",
wantNotes: "release",
},
"with notes file": {
command: "bump --notes-file filename",
wantNotesFilename: "filename",
},
"with target": {
command: "bump --target feature",
wantTarget: "feature",
},
"with title": {
command: "bump -t test_title",
wantTitle: "test_title",
},
"with asset files with comma": {
command: "bump --asset-files file1,file2",
wantAssetFiles: []string{"file1", "file2"},
},
"with asset files with multiple flags": {
command: "bump --asset-files file1 --asset-files file2",
wantAssetFiles: []string{"file1", "file2"},
},
"with bump type": {
command: "bump --bump-type major",
wantBumpType: bump.Major,
},
"with yes": {
command: "bump --yes",
wantYes: true,
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
bumper := &mockBumper{}
cmd := bump.NewRootCmd(bumper)
cmd.SetArgs(strings.Split(tt.command, " ")[1:])
assert.NoError(t, cmd.Execute())
assert.Equal(t, tt.wantRepo, bumper.repository)
assert.Equal(t, tt.wantDraft, bumper.isDraft)
assert.Equal(t, tt.wantPrerelease, bumper.isPrerelease)
assert.Equal(t, tt.wantDiscussionCategory, bumper.discussionCategory)
assert.Equal(t, tt.wantGenerateNotes, bumper.generateNotes)
assert.Equal(t, tt.wantNotes, bumper.notes)
assert.Equal(t, tt.wantNotesFilename, bumper.notesFilename)
assert.Equal(t, tt.wantTarget, bumper.target)
assert.Equal(t, tt.wantTitle, bumper.title)
assert.Equal(t, tt.wantAssetFiles, bumper.assetFiles)
assert.Equal(t, tt.wantBumpType, bumper.bumpType)
assert.Equal(t, tt.wantYes, bumper.yes)
})
}
}