(t *testing.T)
| 575 | } |
| 576 | |
| 577 | func Test_ViewRun_WithoutUsername(t *testing.T) { |
| 578 | reg := &httpmock.Registry{} |
| 579 | reg.Register( |
| 580 | httpmock.GraphQL(`query UserCurrent\b`), |
| 581 | httpmock.StringResponse(` |
| 582 | { "data": { "viewer": { |
| 583 | "login": "OWNER" |
| 584 | }}}`)) |
| 585 | reg.Register( |
| 586 | httpmock.GraphQL(`query RepositoryInfo\b`), |
| 587 | httpmock.StringResponse(` |
| 588 | { "data": { |
| 589 | "repository": { |
| 590 | "description": "social distancing" |
| 591 | } } }`)) |
| 592 | reg.Register( |
| 593 | httpmock.REST("GET", "repos/OWNER/REPO/readme"), |
| 594 | httpmock.StringResponse(` |
| 595 | { "name": "readme.md", |
| 596 | "content": "IyB0cnVseSBjb29sIHJlYWRtZSBjaGVjayBpdCBvdXQ="}`)) |
| 597 | |
| 598 | io, _, stdout, stderr := iostreams.Test() |
| 599 | io.SetStdoutTTY(false) |
| 600 | |
| 601 | opts := &ViewOptions{ |
| 602 | RepoArg: "REPO", |
| 603 | HttpClient: func() (*http.Client, error) { |
| 604 | return &http.Client{Transport: reg}, nil |
| 605 | }, |
| 606 | IO: io, |
| 607 | Config: func() (gh.Config, error) { |
| 608 | return config.NewBlankConfig(), nil |
| 609 | }, |
| 610 | } |
| 611 | |
| 612 | if err := viewRun(opts); err != nil { |
| 613 | t.Errorf("viewRun() error = %v", err) |
| 614 | } |
| 615 | |
| 616 | assert.Equal(t, heredoc.Doc(` |
| 617 | name: OWNER/REPO |
| 618 | description: social distancing |
| 619 | -- |
| 620 | # truly cool readme check it out |
| 621 | `), stdout.String()) |
| 622 | assert.Equal(t, "", stderr.String()) |
| 623 | reg.Verify(t) |
| 624 | } |
| 625 | |
| 626 | func Test_ViewRun_HandlesSpecialCharacters(t *testing.T) { |
| 627 | tests := []struct { |
nothing calls this directly
no test coverage detected