MCPcopy
hub / github.com/cli/cli / runCommand

Function runCommand

pkg/cmd/pr/view/view_test.go:170–203  ·  view source on GitHub ↗
(rt http.RoundTripper, branch string, isTTY bool, cli string)

Source from the content-addressed store, hash-verified

168}
169
170func runCommand(rt http.RoundTripper, branch string, isTTY bool, cli string) (*test.CmdOut, error) {
171 ios, _, stdout, stderr := iostreams.Test()
172 ios.SetStdoutTTY(isTTY)
173 ios.SetStdinTTY(isTTY)
174 ios.SetStderrTTY(isTTY)
175
176 browser := &browser.Stub{}
177 factory := &cmdutil.Factory{
178 IOStreams: ios,
179 Browser: browser,
180 HttpClient: func() (*http.Client, error) {
181 return &http.Client{Transport: rt}, nil
182 },
183 }
184
185 cmd := NewCmdView(factory, nil)
186
187 argv, err := shlex.Split(cli)
188 if err != nil {
189 return nil, err
190 }
191 cmd.SetArgs(argv)
192
193 cmd.SetIn(&bytes.Buffer{})
194 cmd.SetOut(io.Discard)
195 cmd.SetErr(io.Discard)
196
197 _, err = cmd.ExecuteC()
198 return &test.CmdOut{
199 OutBuf: stdout,
200 ErrBuf: stderr,
201 BrowsedURL: browser.BrowsedURL(),
202 }, err
203}
204
205// hack for compatibility with old JSON fixture files
206func prFromFixtures(fixtures map[string]string) (*api.PullRequest, error) {

Callers 6

TestPRView_PreviewFunction · 0.70
TestPRView_tty_CommentsFunction · 0.70

Calls 6

BrowsedURLMethod · 0.95
TestFunction · 0.92
SetStdoutTTYMethod · 0.80
SetStdinTTYMethod · 0.80
SetStderrTTYMethod · 0.80
NewCmdViewFunction · 0.70

Tested by

no test coverage detected