(t *testing.T)
| 470 | } |
| 471 | |
| 472 | func Test_commentRun(t *testing.T) { |
| 473 | tests := []struct { |
| 474 | name string |
| 475 | input *shared.CommentableOptions |
| 476 | emptyComments bool |
| 477 | comments api.Comments |
| 478 | httpStubs func(*testing.T, *httpmock.Registry) |
| 479 | stdout string |
| 480 | stderr string |
| 481 | wantsErr bool |
| 482 | }{ |
| 483 | { |
| 484 | name: "creating new comment with interactive editor succeeds", |
| 485 | input: &shared.CommentableOptions{ |
| 486 | Interactive: true, |
| 487 | InputType: 0, |
| 488 | Body: "", |
| 489 | |
| 490 | InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil }, |
| 491 | ConfirmSubmitSurvey: func() (bool, error) { return true, nil }, |
| 492 | }, |
| 493 | emptyComments: true, |
| 494 | httpStubs: func(t *testing.T, reg *httpmock.Registry) { |
| 495 | mockCommentCreate(t, reg) |
| 496 | }, |
| 497 | stdout: "https://github.com/OWNER/REPO/issues/123#issuecomment-456\n", |
| 498 | }, |
| 499 | { |
| 500 | name: "updating last comment with interactive editor fails if there are no comments and decline prompt to create", |
| 501 | input: &shared.CommentableOptions{ |
| 502 | Interactive: true, |
| 503 | InputType: 0, |
| 504 | Body: "", |
| 505 | EditLast: true, |
| 506 | |
| 507 | InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil }, |
| 508 | ConfirmSubmitSurvey: func() (bool, error) { return true, nil }, |
| 509 | ConfirmCreateIfNoneSurvey: func() (bool, error) { return false, nil }, |
| 510 | }, |
| 511 | emptyComments: true, |
| 512 | wantsErr: true, |
| 513 | stdout: "no comments found for current user", |
| 514 | }, |
| 515 | { |
| 516 | name: "updating last comment with interactive editor succeeds if there are comments", |
| 517 | input: &shared.CommentableOptions{ |
| 518 | Interactive: true, |
| 519 | InputType: 0, |
| 520 | Body: "", |
| 521 | EditLast: true, |
| 522 | |
| 523 | InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil }, |
| 524 | ConfirmSubmitSurvey: func() (bool, error) { return true, nil }, |
| 525 | }, |
| 526 | httpStubs: func(t *testing.T, reg *httpmock.Registry) { |
| 527 | mockCommentUpdate(t, reg) |
| 528 | }, |
| 529 | emptyComments: false, |
nothing calls this directly
no test coverage detected