(t *testing.T)
| 320 | } |
| 321 | |
| 322 | func Test_commentRun(t *testing.T) { |
| 323 | tests := []struct { |
| 324 | name string |
| 325 | input *shared.CommentableOptions |
| 326 | emptyComments bool |
| 327 | comments api.Comments |
| 328 | httpStubs func(*testing.T, *httpmock.Registry) |
| 329 | stdout string |
| 330 | stderr string |
| 331 | wantsErr bool |
| 332 | }{ |
| 333 | { |
| 334 | name: "creating new comment with interactive editor succeeds", |
| 335 | input: &shared.CommentableOptions{ |
| 336 | Interactive: true, |
| 337 | InputType: 0, |
| 338 | Body: "", |
| 339 | |
| 340 | InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil }, |
| 341 | ConfirmSubmitSurvey: func() (bool, error) { return true, nil }, |
| 342 | }, |
| 343 | httpStubs: func(t *testing.T, reg *httpmock.Registry) { |
| 344 | mockCommentCreate(t, reg) |
| 345 | }, |
| 346 | stdout: "https://github.com/OWNER/REPO/pull/123#issuecomment-456\n", |
| 347 | }, |
| 348 | { |
| 349 | name: "updating last comment with interactive editor fails if there are no comments and decline prompt to create", |
| 350 | input: &shared.CommentableOptions{ |
| 351 | Interactive: true, |
| 352 | InputType: 0, |
| 353 | Body: "", |
| 354 | EditLast: true, |
| 355 | |
| 356 | InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil }, |
| 357 | ConfirmSubmitSurvey: func() (bool, error) { return true, nil }, |
| 358 | ConfirmCreateIfNoneSurvey: func() (bool, error) { return false, nil }, |
| 359 | }, |
| 360 | emptyComments: true, |
| 361 | wantsErr: true, |
| 362 | stdout: "no comments found for current user", |
| 363 | }, |
| 364 | { |
| 365 | name: "updating last comment with interactive editor succeeds if there are comments", |
| 366 | input: &shared.CommentableOptions{ |
| 367 | Interactive: true, |
| 368 | InputType: 0, |
| 369 | Body: "", |
| 370 | EditLast: true, |
| 371 | |
| 372 | InteractiveEditSurvey: func(string) (string, error) { return "comment body", nil }, |
| 373 | ConfirmSubmitSurvey: func() (bool, error) { return true, nil }, |
| 374 | }, |
| 375 | httpStubs: func(t *testing.T, reg *httpmock.Registry) { |
| 376 | mockCommentUpdate(t, reg) |
| 377 | }, |
| 378 | emptyComments: false, |
| 379 | stdout: "https://github.com/OWNER/REPO/pull/123#issuecomment-111\n", |
nothing calls this directly
no test coverage detected