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