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

Function Test_commentRun

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

Source from the content-addressed store, hash-verified

513}
514
515func Test_commentRun(t *testing.T) {
516 dir := t.TempDir()
517 shot := filepath.Join(dir, "shot.png")
518 require.NoError(t, os.WriteFile(shot, []byte("shot bytes"), 0600))
519 clip := filepath.Join(dir, "clip.mp4")
520 require.NoError(t, os.WriteFile(clip, []byte("clip bytes"), 0600))
521
522 tests := []struct {
523 name string
524 input *shared.CommentableOptions
525 emptyComments bool
526 comments api.Comments
527 httpStubs func(*testing.T, *httpmock.Registry)
528 stdout string
529 stderr string
530 wantsErr bool
531 wantsErrMsg string
532 }{
533 {
534 name: "creating new comment with interactive editor succeeds",
535 input: &shared.CommentableOptions{
536 Interactive: true,
537 InputType: 0,
538 Body: "",
539
540 InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil },
541 ConfirmSubmitSurvey: func() (bool, error) { return true, nil },
542 },
543 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
544 mockCommentCreate(t, reg, "comment body")
545 },
546 stdout: "https://github.com/OWNER/REPO/pull/123#issuecomment-456\n",
547 },
548 {
549 name: "updating last comment with interactive editor fails if there are no comments and decline prompt to create",
550 input: &shared.CommentableOptions{
551 Interactive: true,
552 InputType: 0,
553 Body: "",
554 EditLast: true,
555
556 InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil },
557 ConfirmSubmitSurvey: func() (bool, error) { return true, nil },
558 ConfirmCreateIfNoneSurvey: func() (bool, error) { return false, nil },
559 },
560 emptyComments: true,
561 wantsErr: true,
562 stdout: "no comments found for current user",
563 },
564 {
565 name: "updating last comment with interactive editor succeeds if there are comments",
566 input: &shared.CommentableOptions{
567 Interactive: true,
568 InputType: 0,
569 Body: "",
570 EditLast: true,
571
572 InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil },

Callers

nothing calls this directly

Calls 15

VerifyMethod · 0.95
ExcludeMethod · 0.95
TestFunction · 0.92
GraphQLFunction · 0.92
NewFunction · 0.92
CommentableRunFunction · 0.92
JoinMethod · 0.80
ContainsMethod · 0.80
SetStdoutTTYMethod · 0.80
SetStdinTTYMethod · 0.80
SetStderrTTYMethod · 0.80
EqualMethod · 0.80

Tested by

no test coverage detected