MCPcopy
hub / github.com/cli/cli / Test_ViewRun_NoReadme

Function Test_ViewRun_NoReadme

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

Source from the content-addressed store, hash-verified

439}
440
441func 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)

Callers

nothing calls this directly

Calls 14

RegisterMethod · 0.95
VerifyMethod · 0.95
GraphQLFunction · 0.92
StringResponseFunction · 0.92
RESTFunction · 0.92
StatusStringResponseFunction · 0.92
NewFunction · 0.92
TestFunction · 0.92
SetStdoutTTYMethod · 0.80
EqualMethod · 0.80
viewRunFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected