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

Function Test_commentRun

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

Source from the content-addressed store, hash-verified

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