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

Function Test_commentRun

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

Source from the content-addressed store, hash-verified

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