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