MCPcopy
hub / github.com/cli/cli / Test_RepoView_Web

Function Test_RepoView_Web

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

Source from the content-addressed store, hash-verified

172}
173
174func Test_RepoView_Web(t *testing.T) {
175 tests := []struct {
176 name string
177 stdoutTTY bool
178 wantStderr string
179 wantBrowse string
180 }{
181 {
182 name: "tty",
183 stdoutTTY: true,
184 wantStderr: "Opening https://github.com/OWNER/REPO in your browser.\n",
185 wantBrowse: "https://github.com/OWNER/REPO",
186 },
187 {
188 name: "nontty",
189 stdoutTTY: false,
190 wantStderr: "",
191 wantBrowse: "https://github.com/OWNER/REPO",
192 },
193 }
194
195 for _, tt := range tests {
196 reg := &httpmock.Registry{}
197 reg.StubRepoInfoResponse("OWNER", "REPO", "main")
198
199 browser := &browser.Stub{}
200 opts := &ViewOptions{
201 Web: true,
202 HttpClient: func() (*http.Client, error) {
203 return &http.Client{Transport: reg}, nil
204 },
205 BaseRepo: func() (ghrepo.Interface, error) {
206 return ghrepo.New("OWNER", "REPO"), nil
207 },
208 Browser: browser,
209 }
210
211 io, _, stdout, stderr := iostreams.Test()
212
213 opts.IO = io
214
215 t.Run(tt.name, func(t *testing.T) {
216 io.SetStdoutTTY(tt.stdoutTTY)
217
218 _, teardown := run.Stub()
219 defer teardown(t)
220
221 if err := viewRun(opts); err != nil {
222 t.Errorf("viewRun() error = %v", err)
223 }
224 assert.Equal(t, "", stdout.String())
225 assert.Equal(t, tt.wantStderr, stderr.String())
226 reg.Verify(t)
227 browser.Verify(t, tt.wantBrowse)
228 })
229 }
230}
231

Callers

nothing calls this directly

Calls 12

StubRepoInfoResponseMethod · 0.95
VerifyMethod · 0.95
VerifyMethod · 0.95
NewFunction · 0.92
TestFunction · 0.92
StubFunction · 0.92
SetStdoutTTYMethod · 0.80
EqualMethod · 0.80
viewRunFunction · 0.70
RunMethod · 0.65
ErrorfMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected