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

Function Test_commentRun

pkg/cmd/pr/comment/comment_test.go:322–701  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

320}
321
322func Test_commentRun(t *testing.T) {
323 tests := []struct {
324 name string
325 input *shared.CommentableOptions
326 emptyComments bool
327 comments api.Comments
328 httpStubs func(*testing.T, *httpmock.Registry)
329 stdout string
330 stderr string
331 wantsErr bool
332 }{
333 {
334 name: "creating new comment with interactive editor succeeds",
335 input: &shared.CommentableOptions{
336 Interactive: true,
337 InputType: 0,
338 Body: "",
339
340 InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil },
341 ConfirmSubmitSurvey: func() (bool, error) { return true, nil },
342 },
343 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
344 mockCommentCreate(t, reg)
345 },
346 stdout: "https://github.com/OWNER/REPO/pull/123#issuecomment-456\n",
347 },
348 {
349 name: "updating last comment with interactive editor fails if there are no comments and decline prompt to create",
350 input: &shared.CommentableOptions{
351 Interactive: true,
352 InputType: 0,
353 Body: "",
354 EditLast: true,
355
356 InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil },
357 ConfirmSubmitSurvey: func() (bool, error) { return true, nil },
358 ConfirmCreateIfNoneSurvey: func() (bool, error) { return false, nil },
359 },
360 emptyComments: true,
361 wantsErr: true,
362 stdout: "no comments found for current user",
363 },
364 {
365 name: "updating last comment with interactive editor succeeds if there are comments",
366 input: &shared.CommentableOptions{
367 Interactive: true,
368 InputType: 0,
369 Body: "",
370 EditLast: true,
371
372 InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil },
373 ConfirmSubmitSurvey: func() (bool, error) { return true, nil },
374 },
375 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
376 mockCommentUpdate(t, reg)
377 },
378 emptyComments: false,
379 stdout: "https://github.com/OWNER/REPO/pull/123#issuecomment-111\n",

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