MCPcopy
hub / github.com/cli/cli / TestRemoteGuessing

Function TestRemoteGuessing

pkg/cmd/pr/create/create_test.go:2182–2267  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2180}
2181
2182func TestRemoteGuessing(t *testing.T) {
2183 // Given git config does not provide the necessary info to determine a remote
2184 cs, cmdTeardown := run.Stub()
2185 defer cmdTeardown(t)
2186
2187 cs.Register(`git status --porcelain`, 0, "")
2188 cs.Register(`git config --get-regexp \^branch\\\..+\\\.\(remote\|merge\|pushremote\|gh-merge-base\)\$`, 0, "")
2189 cs.Register(`git rev-parse --symbolic-full-name feature@{push}`, 1, "")
2190 cs.Register("git config remote.pushDefault", 1, "")
2191 cs.Register("git config push.default", 1, "")
2192
2193 // And Given there is a remote on a SHA that matches the current HEAD
2194 cs.Register(`git show-ref --verify -- HEAD refs/remotes/upstream/feature refs/remotes/origin/feature`, 0, heredoc.Doc(`
2195 deadbeef HEAD
2196 deadb00f refs/remotes/upstream/feature
2197 deadbeef refs/remotes/origin/feature`))
2198
2199 // When the command is run
2200 reg := &httpmock.Registry{}
2201 reg.StubRepoInfoResponse("OWNER", "REPO", "master")
2202 defer reg.Verify(t)
2203
2204 reg.Register(
2205 httpmock.GraphQL(`mutation PullRequestCreate\b`),
2206 httpmock.GraphQLMutation(`
2207 { "data": { "createPullRequest": { "pullRequest": {
2208 "URL": "https://github.com/OWNER/REPO/pull/12"
2209 } } } }`, func(input map[string]interface{}) {
2210 assert.Equal(t, "REPOID", input["repositoryId"].(string))
2211 assert.Equal(t, "master", input["baseRefName"].(string))
2212 assert.Equal(t, "OTHEROWNER:feature", input["headRefName"].(string))
2213 }))
2214
2215 ios, _, _, _ := iostreams.Test()
2216
2217 opts := CreateOptions{
2218 HttpClient: func() (*http.Client, error) {
2219 return &http.Client{Transport: reg}, nil
2220 },
2221 Config: func() (gh.Config, error) {
2222 return config.NewBlankConfig(), nil
2223 },
2224 Browser: &browser.Stub{},
2225 IO: ios,
2226 Prompter: &prompter.PrompterMock{},
2227 GitClient: &git.Client{
2228 GhPath: "some/path/gh",
2229 GitPath: "some/path/git",
2230 },
2231 Finder: shared.NewMockFinder("feature", nil, nil),
2232 Remotes: func() (context.Remotes, error) {
2233 return context.Remotes{
2234 {
2235 Remote: &git.Remote{
2236 Name: "upstream",
2237 Resolved: "base",
2238 },
2239 Repo: ghrepo.New("OWNER", "REPO"),

Callers

nothing calls this directly

Calls 12

RegisterMethod · 0.95
StubRepoInfoResponseMethod · 0.95
VerifyMethod · 0.95
StubFunction · 0.92
GraphQLFunction · 0.92
GraphQLMutationFunction · 0.92
TestFunction · 0.92
NewBlankConfigFunction · 0.92
NewMockFinderFunction · 0.92
NewFunction · 0.92
EqualMethod · 0.80
createRunFunction · 0.70

Tested by

no test coverage detected