MCPcopy
hub / github.com/cli/cli / Test_ViewRun_WithoutUsername

Function Test_ViewRun_WithoutUsername

pkg/cmd/repo/view/view_test.go:577–624  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

575}
576
577func 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
626func Test_ViewRun_HandlesSpecialCharacters(t *testing.T) {
627 tests := []struct {

Callers

nothing calls this directly

Calls 12

RegisterMethod · 0.95
VerifyMethod · 0.95
GraphQLFunction · 0.92
StringResponseFunction · 0.92
RESTFunction · 0.92
TestFunction · 0.92
NewBlankConfigFunction · 0.92
SetStdoutTTYMethod · 0.80
EqualMethod · 0.80
viewRunFunction · 0.70
ErrorfMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected