MCPcopy
hub / github.com/cli/cli / TestRepoFork

Function TestRepoFork

pkg/cmd/repo/fork/fork_test.go:197–806  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

195}
196
197func TestRepoFork(t *testing.T) {
198 forkResult := `{
199 "node_id": "123",
200 "name": "REPO",
201 "clone_url": "https://github.com/someone/repo.git",
202 "created_at": "2011-01-26T19:01:12Z",
203 "owner": {
204 "login": "someone"
205 }
206 }`
207
208 forkPost := func(reg *httpmock.Registry) {
209 reg.Register(
210 httpmock.REST("POST", "repos/OWNER/REPO/forks"),
211 httpmock.StringResponse(forkResult))
212 }
213
214 tests := []struct {
215 name string
216 opts *ForkOptions
217 tty bool
218 httpStubs func(*httpmock.Registry)
219 execStubs func(*run.CommandStubber)
220 promptStubs func(*prompter.MockPrompter)
221 cfgStubs func(*testing.T, gh.Config)
222 remotes []*context.Remote
223 wantOut string
224 wantErrOut string
225 wantErr bool
226 errMsg string
227 }{
228 {
229 name: "implicit match, configured protocol overrides provided",
230 tty: true,
231 opts: &ForkOptions{
232 Remote: true,
233 RemoteName: "fork",
234 },
235 remotes: []*context.Remote{
236 {
237 Remote: &git.Remote{Name: "origin", PushURL: &url.URL{
238 Scheme: "ssh",
239 }},
240 Repo: ghrepo.New("OWNER", "REPO"),
241 },
242 },
243 cfgStubs: func(_ *testing.T, c gh.Config) {
244 c.Set("", "git_protocol", "https")
245 },
246 httpStubs: forkPost,
247 execStubs: func(cs *run.CommandStubber) {
248 cs.Register(`git remote add fork https://github\.com/someone/REPO\.git`, 0, "")
249 },
250 wantErrOut: "✓ Created fork someone/REPO\n✓ Added remote fork\n",
251 },
252 {
253 name: "implicit match, no configured protocol",
254 tty: true,

Callers

nothing calls this directly

Calls 15

RegisterMethod · 0.95
VerifyMethod · 0.95
RESTFunction · 0.92
StringResponseFunction · 0.92
NewFunction · 0.92
TestFunction · 0.92
NewIsolatedTestConfigFunction · 0.92
NewMockPrompterFunction · 0.92
StubFunction · 0.92
forkRunFunction · 0.85
EqualMethod · 0.80
SetStdinTTYMethod · 0.80

Tested by

no test coverage detected