MCPcopy Index your code
hub / github.com/cli/cli / Test_commentRun

Function Test_commentRun

pkg/cmd/issue/comment/comment_test.go:300–682  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

298}
299
300func Test_commentRun(t *testing.T) {
301 tests := []struct {
302 name string
303 input *shared.CommentableOptions
304 emptyComments bool
305 comments api.Comments
306 httpStubs func(*testing.T, *httpmock.Registry)
307 stdout string
308 stderr string
309 wantsErr bool
310 }{
311 {
312 name: "creating new comment with interactive editor succeeds",
313 input: &shared.CommentableOptions{
314 Interactive: true,
315 InputType: 0,
316 Body: "",
317
318 InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil },
319 ConfirmSubmitSurvey: func() (bool, error) { return true, nil },
320 },
321 emptyComments: true,
322 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
323 mockCommentCreate(t, reg)
324 },
325 stdout: "https://github.com/OWNER/REPO/issues/123#issuecomment-456\n",
326 },
327 {
328 name: "updating last comment with interactive editor fails if there are no comments and decline prompt to create",
329 input: &shared.CommentableOptions{
330 Interactive: true,
331 InputType: 0,
332 Body: "",
333 EditLast: true,
334
335 InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil },
336 ConfirmSubmitSurvey: func() (bool, error) { return true, nil },
337 ConfirmCreateIfNoneSurvey: func() (bool, error) { return false, nil },
338 },
339 emptyComments: true,
340 wantsErr: true,
341 stdout: "no comments found for current user",
342 },
343 {
344 name: "updating last comment with interactive editor succeeds if there are comments",
345 input: &shared.CommentableOptions{
346 Interactive: true,
347 InputType: 0,
348 Body: "",
349 EditLast: true,
350
351 InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil },
352 ConfirmSubmitSurvey: func() (bool, error) { return true, nil },
353 },
354 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
355 mockCommentUpdate(t, reg)
356 },
357 emptyComments: false,

Callers

nothing calls this directly

Calls 15

VerifyMethod · 0.95
TestFunction · 0.92
NewFunction · 0.92
CommentableRunFunction · 0.92
ContainsMethod · 0.80
SetStdoutTTYMethod · 0.80
SetStdinTTYMethod · 0.80
SetStderrTTYMethod · 0.80
EqualMethod · 0.80
mockCommentCreateFunction · 0.70
mockCommentUpdateFunction · 0.70
mockCommentDeleteFunction · 0.70

Tested by

no test coverage detected