MCPcopy Create free account
hub / github.com/cli/cli / Test_commentRun

Function Test_commentRun

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

Source from the content-addressed store, hash-verified

455}
456
457func Test_commentRun(t *testing.T) {
458 tests := []struct {
459 name string
460 input *shared.CommentableOptions
461 emptyComments bool
462 comments api.Comments
463 httpStubs func(*testing.T, *httpmock.Registry)
464 stdout string
465 stderr string
466 wantsErr bool
467 }{
468 {
469 name: "creating new comment with interactive editor succeeds",
470 input: &shared.CommentableOptions{
471 Interactive: true,
472 InputType: 0,
473 Body: "",
474
475 InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil },
476 ConfirmSubmitSurvey: func() (bool, error) { return true, nil },
477 },
478 emptyComments: true,
479 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
480 mockCommentCreate(t, reg)
481 },
482 stdout: "https://github.com/OWNER/REPO/issues/123#issuecomment-456\n",
483 },
484 {
485 name: "updating last comment with interactive editor fails if there are no comments and decline prompt to create",
486 input: &shared.CommentableOptions{
487 Interactive: true,
488 InputType: 0,
489 Body: "",
490 EditLast: true,
491
492 InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil },
493 ConfirmSubmitSurvey: func() (bool, error) { return true, nil },
494 ConfirmCreateIfNoneSurvey: func() (bool, error) { return false, nil },
495 },
496 emptyComments: true,
497 wantsErr: true,
498 stdout: "no comments found for current user",
499 },
500 {
501 name: "updating last comment with interactive editor succeeds if there are comments",
502 input: &shared.CommentableOptions{
503 Interactive: true,
504 InputType: 0,
505 Body: "",
506 EditLast: true,
507
508 InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil },
509 ConfirmSubmitSurvey: func() (bool, error) { return true, nil },
510 },
511 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
512 mockCommentUpdate(t, reg)
513 },
514 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