MCPcopy
hub / github.com/cli/cli / TestCreateRun

Function TestCreateRun

pkg/cmd/discussion/create/create_test.go:144–460  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

142}
143
144func TestCreateRun(t *testing.T) {
145 tests := []struct {
146 name string
147 opts CreateOptions
148 isTTY bool
149 stdinContent string
150 setupMock func(*client.DiscussionClientMock)
151 prompter *prompter.PrompterMock
152 wantErr string
153 wantOut string
154 }{
155 {
156 name: "success non-tty",
157 opts: CreateOptions{
158 Title: "My question",
159 Body: "Details",
160 Category: "Q&A",
161 },
162 setupMock: func(m *client.DiscussionClientMock) {
163 m.ListCategoriesFunc = func(repo ghrepo.Interface) ([]client.DiscussionCategory, error) {
164 return sampleCategories(), nil
165 }
166 m.CreateFunc = func(repo ghrepo.Interface, input client.CreateDiscussionInput) (*client.Discussion, error) {
167 assert.Equal(t, "CAT2", input.CategoryID)
168 assert.Equal(t, "My question", input.Title)
169 assert.Equal(t, "Details", input.Body)
170 return sampleDiscussion(), nil
171 }
172 },
173 wantOut: "https://github.com/OWNER/REPO/discussions/5\n",
174 },
175 {
176 name: "success non-tty with label",
177 opts: CreateOptions{
178 Title: "Feature request",
179 Body: "Details",
180 Category: "general",
181 Labels: []string{"enhancement", "bug"},
182 },
183 setupMock: func(m *client.DiscussionClientMock) {
184 m.ListCategoriesFunc = func(repo ghrepo.Interface) ([]client.DiscussionCategory, error) {
185 return sampleCategories(), nil
186 }
187 m.ListLabelsFunc = func(repo ghrepo.Interface) ([]client.DiscussionLabel, error) {
188 return []client.DiscussionLabel{
189 {ID: "L_bug", Name: "bug"},
190 {ID: "L_enh", Name: "enhancement"},
191 }, nil
192 }
193 m.CreateFunc = func(repo ghrepo.Interface, input client.CreateDiscussionInput) (*client.Discussion, error) {
194 assert.Equal(t, []string{"L_enh", "L_bug"}, input.LabelIDs)
195 return sampleDiscussion(), nil
196 }
197 },
198 wantOut: "https://github.com/OWNER/REPO/discussions/5\n",
199 },
200 {
201 name: "success non-tty body-file from stdin",

Callers

nothing calls this directly

Calls 13

TestFunction · 0.92
NewFunction · 0.92
EqualMethod · 0.80
SetStdoutTTYMethod · 0.80
SetStdinTTYMethod · 0.80
ContainsMethod · 0.80
sampleCategoriesFunction · 0.70
sampleDiscussionFunction · 0.70
createRunFunction · 0.70
ErrorfMethod · 0.65
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected