(rt http.RoundTripper, branch string, isTTY bool, cli string, detector fd.Detector)
| 28 | } |
| 29 | |
| 30 | func runCommandWithDetector(rt http.RoundTripper, branch string, isTTY bool, cli string, detector fd.Detector) (*test.CmdOut, error) { |
| 31 | ios, _, stdout, stderr := iostreams.Test() |
| 32 | ios.SetStdoutTTY(isTTY) |
| 33 | ios.SetStdinTTY(isTTY) |
| 34 | ios.SetStderrTTY(isTTY) |
| 35 | |
| 36 | factory := &cmdutil.Factory{ |
| 37 | IOStreams: ios, |
| 38 | HttpClient: func() (*http.Client, error) { |
| 39 | return &http.Client{Transport: rt}, nil |
| 40 | }, |
| 41 | Config: func() (gh.Config, error) { |
| 42 | return config.NewBlankConfig(), nil |
| 43 | }, |
| 44 | BaseRepo: func() (ghrepo.Interface, error) { |
| 45 | return ghrepo.New("OWNER", "REPO"), nil |
| 46 | }, |
| 47 | Remotes: func() (context.Remotes, error) { |
| 48 | return context.Remotes{ |
| 49 | { |
| 50 | Remote: &git.Remote{Name: "origin"}, |
| 51 | Repo: ghrepo.New("OWNER", "REPO"), |
| 52 | }, |
| 53 | }, nil |
| 54 | }, |
| 55 | Branch: func() (string, error) { |
| 56 | if branch == "" { |
| 57 | return "", git.ErrNotOnAnyBranch |
| 58 | } |
| 59 | return branch, nil |
| 60 | }, |
| 61 | GitClient: &git.Client{GitPath: "some/path/git"}, |
| 62 | } |
| 63 | |
| 64 | withProvidedDetector := func(opts *StatusOptions) error { |
| 65 | opts.Detector = detector |
| 66 | return statusRun(opts) |
| 67 | } |
| 68 | |
| 69 | cmd := NewCmdStatus(factory, withProvidedDetector) |
| 70 | cmd.PersistentFlags().StringP("repo", "R", "", "") |
| 71 | |
| 72 | argv, err := shlex.Split(cli) |
| 73 | if err != nil { |
| 74 | return nil, err |
| 75 | } |
| 76 | cmd.SetArgs(argv) |
| 77 | |
| 78 | cmd.SetIn(&bytes.Buffer{}) |
| 79 | cmd.SetOut(io.Discard) |
| 80 | cmd.SetErr(io.Discard) |
| 81 | |
| 82 | _, err = cmd.ExecuteC() |
| 83 | return &test.CmdOut{ |
| 84 | OutBuf: stdout, |
| 85 | ErrBuf: stderr, |
| 86 | }, err |
| 87 | } |
no test coverage detected