MCPcopy Create free account
hub / github.com/cli/cli / TestViewRun

Function TestViewRun

pkg/cmd/discussion/view/view_test.go:285–1088  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

283}
284
285func TestViewRun(t *testing.T) {
286 fixedNow := func() time.Time { return time.Date(2025, 3, 1, 1, 0, 0, 0, time.UTC) }
287
288 tests := []struct {
289 name string
290 tty bool
291 clientStub func(*testing.T, *client.DiscussionClientMock)
292 opts ViewOptions
293 wantStdout string
294 wantStderr string
295 wantBrowser string
296 }{
297 {
298 name: "tty",
299 tty: true,
300 clientStub: func(t *testing.T, m *client.DiscussionClientMock) {
301 m.GetByNumberFunc = func(repo ghrepo.Interface, number int32) (*client.Discussion, error) {
302 assert.Equal(t, "OWNER/REPO", ghrepo.FullName(repo))
303 assert.Equal(t, int32(123), number)
304 return exampleAnswerableDiscussion(), nil
305 }
306 },
307 wantStdout: heredoc.Doc(`
308 an interesting question #123
309 Open • Q&A • Asked by monalisa • about 1 hour ago • 3 comments
310 Labels: help-wanted
311
312
313 about my interesting question
314
315
316 👍 5 • 🚀 2
317
318 View this discussion on GitHub: https://github.com/OWNER/REPO/discussions/123
319 `),
320 },
321 {
322 name: "nontty",
323 clientStub: func(t *testing.T, m *client.DiscussionClientMock) {
324 m.GetByNumberFunc = func(repo ghrepo.Interface, number int32) (*client.Discussion, error) {
325 assert.Equal(t, "OWNER/REPO", ghrepo.FullName(repo))
326 assert.Equal(t, int32(123), number)
327 return exampleAnswerableDiscussion(), nil
328 }
329 },
330 wantStdout: heredoc.Doc(`
331 title: an interesting question
332 state: OPEN
333 category: Q&A
334 author: monalisa
335 labels: help-wanted
336 comments: 3
337 number: 123
338 url: https://github.com/OWNER/REPO/discussions/123
339 --
340 about my interesting question
341 `),
342 },

Callers

nothing calls this directly

Calls 15

VerifyMethod · 0.95
FullNameFunction · 0.92
TestFunction · 0.92
NewFunction · 0.92
EqualMethod · 0.80
SetStdoutTTYMethod · 0.80
SetStderrTTYMethod · 0.80
jsonExporterFunction · 0.70

Tested by

no test coverage detected