TODO port to new style tests
(rt http.RoundTripper, pm *prompter.PrompterMock, branch string, isTTY bool, cli string)
| 249 | |
| 250 | // TODO port to new style tests |
| 251 | func runCommand(rt http.RoundTripper, pm *prompter.PrompterMock, branch string, isTTY bool, cli string) (*test.CmdOut, error) { |
| 252 | ios, _, stdout, stderr := iostreams.Test() |
| 253 | ios.SetStdoutTTY(isTTY) |
| 254 | ios.SetStdinTTY(isTTY) |
| 255 | ios.SetStderrTTY(isTTY) |
| 256 | |
| 257 | factory := &cmdutil.Factory{ |
| 258 | IOStreams: ios, |
| 259 | HttpClient: func() (*http.Client, error) { |
| 260 | return &http.Client{Transport: rt}, nil |
| 261 | }, |
| 262 | Branch: func() (string, error) { |
| 263 | return branch, nil |
| 264 | }, |
| 265 | Remotes: func() (context.Remotes, error) { |
| 266 | return []*context.Remote{ |
| 267 | { |
| 268 | Remote: &git.Remote{ |
| 269 | Name: "origin", |
| 270 | }, |
| 271 | Repo: ghrepo.New("OWNER", "REPO"), |
| 272 | }, |
| 273 | }, nil |
| 274 | }, |
| 275 | GitClient: &git.Client{ |
| 276 | GhPath: "some/path/gh", |
| 277 | GitPath: "some/path/git", |
| 278 | }, |
| 279 | Prompter: pm, |
| 280 | } |
| 281 | |
| 282 | cmd := NewCmdMerge(factory, nil) |
| 283 | cmd.PersistentFlags().StringP("repo", "R", "", "") |
| 284 | |
| 285 | cli = strings.TrimPrefix(cli, "pr merge") |
| 286 | argv, err := shlex.Split(cli) |
| 287 | if err != nil { |
| 288 | return nil, err |
| 289 | } |
| 290 | cmd.SetArgs(argv) |
| 291 | |
| 292 | cmd.SetIn(&bytes.Buffer{}) |
| 293 | cmd.SetOut(io.Discard) |
| 294 | cmd.SetErr(io.Discard) |
| 295 | |
| 296 | _, err = cmd.ExecuteC() |
| 297 | return &test.CmdOut{ |
| 298 | OutBuf: stdout, |
| 299 | ErrBuf: stderr, |
| 300 | }, err |
| 301 | } |
| 302 | |
| 303 | func initFakeHTTP() *httpmock.Registry { |
| 304 | return &httpmock.Registry{} |
no test coverage detected