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

Function Test_commentRun

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

Source from the content-addressed store, hash-verified

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

Tested by

no test coverage detected