(t *testing.T)
| 569 | } |
| 570 | |
| 571 | func 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, |
nothing calls this directly
no test coverage detected