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

Function Test_commentRun

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

Source from the content-addressed store, hash-verified

569}
570
571func Test_commentRun(t *testing.T) {
572 tests := []struct {
573 name string
574 input *shared.CommentableOptions
575 emptyComments bool
576 comments api.Comments
577 httpStubs func(*testing.T, *httpmock.Registry)
578 stdout string
579 stderr string
580 wantsErr bool
581 }{
582 {
583 name: "creating new comment with interactive editor succeeds",
584 input: &shared.CommentableOptions{
585 Interactive: true,
586 InputType: 0,
587 Body: "",
588
589 InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil },
590 ConfirmSubmitSurvey: func() (bool, error) { return true, nil },
591 },
592 emptyComments: true,
593 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
594 mockCommentCreate(t, reg)
595 },
596 stdout: "https://github.com/OWNER/REPO/issues/123#issuecomment-456\n",
597 },
598 {
599 name: "updating last comment with interactive editor fails if there are no comments and decline prompt to create",
600 input: &shared.CommentableOptions{
601 Interactive: true,
602 InputType: 0,
603 Body: "",
604 EditLast: true,
605
606 InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil },
607 ConfirmSubmitSurvey: func() (bool, error) { return true, nil },
608 ConfirmCreateIfNoneSurvey: func() (bool, error) { return false, nil },
609 },
610 emptyComments: true,
611 wantsErr: true,
612 stdout: "no comments found for current user",
613 },
614 {
615 name: "updating last comment with interactive editor succeeds if there are comments",
616 input: &shared.CommentableOptions{
617 Interactive: true,
618 InputType: 0,
619 Body: "",
620 EditLast: true,
621
622 InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil },
623 ConfirmSubmitSurvey: func() (bool, error) { return true, nil },
624 },
625 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
626 mockCommentUpdate(t, reg)
627 },
628 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