(t *testing.T)
| 492 | } |
| 493 | |
| 494 | func Test_commentRun(t *testing.T) { |
| 495 | dir := t.TempDir() |
| 496 | shot := filepath.Join(dir, "shot.png") |
| 497 | require.NoError(t, os.WriteFile(shot, []byte("shot bytes"), 0600)) |
| 498 | clip := filepath.Join(dir, "clip.mp4") |
| 499 | require.NoError(t, os.WriteFile(clip, []byte("clip bytes"), 0600)) |
| 500 | |
| 501 | tests := []struct { |
| 502 | name string |
| 503 | input *shared.CommentableOptions |
| 504 | emptyComments bool |
| 505 | comments api.Comments |
| 506 | httpStubs func(*testing.T, *httpmock.Registry) |
| 507 | stdout string |
| 508 | stderr string |
| 509 | wantsErr bool |
| 510 | wantsErrMsg string |
| 511 | }{ |
| 512 | { |
| 513 | name: "creating new comment with interactive editor succeeds", |
| 514 | input: &shared.CommentableOptions{ |
| 515 | Interactive: true, |
| 516 | InputType: 0, |
| 517 | Body: "", |
| 518 | |
| 519 | InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil }, |
| 520 | ConfirmSubmitSurvey: func() (bool, error) { return true, nil }, |
| 521 | }, |
| 522 | httpStubs: func(t *testing.T, reg *httpmock.Registry) { |
| 523 | mockCommentCreate(t, reg, "comment body") |
| 524 | }, |
| 525 | stdout: "https://github.com/OWNER/REPO/pull/123#issuecomment-456\n", |
| 526 | }, |
| 527 | { |
| 528 | name: "updating last comment with interactive editor fails if there are no comments and decline prompt to create", |
| 529 | input: &shared.CommentableOptions{ |
| 530 | Interactive: true, |
| 531 | InputType: 0, |
| 532 | Body: "", |
| 533 | EditLast: true, |
| 534 | |
| 535 | InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil }, |
| 536 | ConfirmSubmitSurvey: func() (bool, error) { return true, nil }, |
| 537 | ConfirmCreateIfNoneSurvey: func() (bool, error) { return false, nil }, |
| 538 | }, |
| 539 | emptyComments: true, |
| 540 | wantsErr: true, |
| 541 | stdout: "no comments found for current user", |
| 542 | }, |
| 543 | { |
| 544 | name: "updating last comment with interactive editor succeeds if there are comments", |
| 545 | input: &shared.CommentableOptions{ |
| 546 | Interactive: true, |
| 547 | InputType: 0, |
| 548 | Body: "", |
| 549 | EditLast: true, |
| 550 | |
| 551 | InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil }, |
nothing calls this directly
no test coverage detected