MCPcopy Index your code
hub / github.com/cli/cli / TestNewCmdView

Function TestNewCmdView

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

Source from the content-addressed store, hash-verified

94}
95
96func TestNewCmdView(t *testing.T) {
97 tests := []struct {
98 name string
99 cli string
100 wants ViewOptions
101 wantsErr bool
102 }{
103 {
104 name: "no args",
105 cli: "",
106 wants: ViewOptions{
107 RepoArg: "",
108 Web: false,
109 },
110 },
111 {
112 name: "sets repo arg",
113 cli: "some/repo",
114 wants: ViewOptions{
115 RepoArg: "some/repo",
116 Web: false,
117 },
118 },
119 {
120 name: "sets web",
121 cli: "-w",
122 wants: ViewOptions{
123 RepoArg: "",
124 Web: true,
125 },
126 },
127 {
128 name: "sets branch",
129 cli: "-b feat/awesome",
130 wants: ViewOptions{
131 RepoArg: "",
132 Branch: "feat/awesome",
133 },
134 },
135 }
136
137 for _, tt := range tests {
138 t.Run(tt.name, func(t *testing.T) {
139 io, _, _, _ := iostreams.Test()
140
141 f := &cmdutil.Factory{
142 IOStreams: io,
143 }
144
145 // THOUGHT: this seems ripe for cmdutil. It's almost identical to the set up for the same test
146 // in gist create.
147 argv, err := shlex.Split(tt.cli)
148 assert.NoError(t, err)
149
150 var gotOpts *ViewOptions
151 cmd := NewCmdView(f, func(opts *ViewOptions) error {
152 gotOpts = opts
153 return nil

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