(t *testing.T)
| 439 | } |
| 440 | |
| 441 | func Test_ViewRun_NoReadme(t *testing.T) { |
| 442 | tests := []struct { |
| 443 | name string |
| 444 | stdoutTTY bool |
| 445 | wantOut string |
| 446 | }{ |
| 447 | { |
| 448 | name: "tty", |
| 449 | wantOut: heredoc.Doc(` |
| 450 | OWNER/REPO |
| 451 | social distancing |
| 452 | |
| 453 | This repository does not have a README |
| 454 | |
| 455 | View this repository on GitHub: https://github.com/OWNER/REPO |
| 456 | `), |
| 457 | stdoutTTY: true, |
| 458 | }, |
| 459 | { |
| 460 | name: "nontty", |
| 461 | wantOut: heredoc.Doc(` |
| 462 | name: OWNER/REPO |
| 463 | description: social distancing |
| 464 | `), |
| 465 | }, |
| 466 | } |
| 467 | |
| 468 | for _, tt := range tests { |
| 469 | reg := &httpmock.Registry{} |
| 470 | reg.Register( |
| 471 | httpmock.GraphQL(`query RepositoryInfo\b`), |
| 472 | httpmock.StringResponse(` |
| 473 | { "data": { |
| 474 | "repository": { |
| 475 | "description": "social distancing" |
| 476 | } } }`)) |
| 477 | reg.Register( |
| 478 | httpmock.REST("GET", "repos/OWNER/REPO/readme"), |
| 479 | httpmock.StatusStringResponse(404, `{}`)) |
| 480 | |
| 481 | opts := &ViewOptions{ |
| 482 | HttpClient: func() (*http.Client, error) { |
| 483 | return &http.Client{Transport: reg}, nil |
| 484 | }, |
| 485 | BaseRepo: func() (ghrepo.Interface, error) { |
| 486 | return ghrepo.New("OWNER", "REPO"), nil |
| 487 | }, |
| 488 | } |
| 489 | |
| 490 | io, _, stdout, stderr := iostreams.Test() |
| 491 | |
| 492 | opts.IO = io |
| 493 | |
| 494 | t.Run(tt.name, func(t *testing.T) { |
| 495 | io.SetStdoutTTY(tt.stdoutTTY) |
| 496 | |
| 497 | if err := viewRun(opts); err != nil { |
| 498 | t.Errorf("viewRun() error = %v", err) |
nothing calls this directly
no test coverage detected