MCPcopy
hub / github.com/cli/cli / TestNewCmdview

Function TestNewCmdview

pkg/cmd/project/view/view_test.go:16–92  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestNewCmdview(t *testing.T) {
17 tests := []struct {
18 name string
19 cli string
20 wants viewOpts
21 wantsErr bool
22 wantsErrMsg string
23 wantsExporter bool
24 }{
25 {
26 name: "not-a-number",
27 cli: "x",
28 wantsErr: true,
29 wantsErrMsg: "invalid number: x",
30 },
31 {
32 name: "number",
33 cli: "123",
34 wants: viewOpts{
35 number: 123,
36 },
37 },
38 {
39 name: "owner",
40 cli: "--owner monalisa",
41 wants: viewOpts{
42 owner: "monalisa",
43 },
44 },
45 {
46 name: "web",
47 cli: "--web",
48 wants: viewOpts{
49 web: true,
50 },
51 },
52 {
53 name: "json",
54 cli: "--format json",
55 wantsExporter: true,
56 },
57 }
58
59 t.Setenv("GH_TOKEN", "auth-token")
60
61 for _, tt := range tests {
62 t.Run(tt.name, func(t *testing.T) {
63 ios, _, _, _ := iostreams.Test()
64 f := &cmdutil.Factory{
65 IOStreams: ios,
66 }
67
68 argv, err := shlex.Split(tt.cli)
69 assert.NoError(t, err)
70
71 var gotOpts viewOpts
72 cmd := NewCmdView(f, func(config viewConfig) error {
73 gotOpts = config.opts

Callers

nothing calls this directly

Calls 5

TestFunction · 0.92
EqualMethod · 0.80
NewCmdViewFunction · 0.70
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected