MCPcopy Create free account
hub / github.com/cli/cli / TestRemoteGuessing

Function TestRemoteGuessing

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

Source from the content-addressed store, hash-verified

2639}
2640
2641func TestRemoteGuessing(t *testing.T) {
2642 // Given git config does not provide the necessary info to determine a remote
2643 cs, cmdTeardown := run.Stub()
2644 defer cmdTeardown(t)
2645
2646 cs.Register(`git status --porcelain`, 0, "")
2647 cs.Register(`git config --get-regexp \^branch\\\..+\\\.\(remote\|merge\|pushremote\|gh-merge-base\)\$`, 0, "")
2648 cs.Register(`git rev-parse --symbolic-full-name feature@{push}`, 1, "")
2649 cs.Register("git config remote.pushDefault", 1, "")
2650 cs.Register("git config push.default", 1, "")
2651
2652 // And Given there is a remote on a SHA that matches the current HEAD
2653 cs.Register(`git show-ref --verify -- HEAD refs/remotes/upstream/feature refs/remotes/origin/feature`, 0, heredoc.Doc(`
2654 deadbeef HEAD
2655 deadb00f refs/remotes/upstream/feature
2656 deadbeef refs/remotes/origin/feature`))
2657
2658 // When the command is run
2659 reg := &httpmock.Registry{}
2660 reg.StubRepoInfoResponse("OWNER", "REPO", "master")
2661 defer reg.Verify(t)
2662
2663 reg.Register(
2664 httpmock.GraphQL(`mutation PullRequestCreate\b`),
2665 httpmock.GraphQLMutation(`
2666 { "data": { "createPullRequest": { "pullRequest": {
2667 "URL": "https://github.com/OWNER/REPO/pull/12"
2668 } } } }`, func(input map[string]any) {
2669 assert.Equal(t, "REPOID", input["repositoryId"].(string))
2670 assert.Equal(t, "master", input["baseRefName"].(string))
2671 assert.Equal(t, "OTHEROWNER:feature", input["headRefName"].(string))
2672 }))
2673
2674 ios, _, _, _ := iostreams.Test()
2675
2676 opts := CreateOptions{
2677 HttpClient: func() (*http.Client, error) {
2678 return &http.Client{Transport: reg}, nil
2679 },
2680 Config: func() (gh.Config, error) {
2681 return config.NewMockConfig(), nil
2682 },
2683 Browser: &browser.Stub{},
2684 IO: ios,
2685 Prompter: &prompter.PrompterMock{},
2686 GitClient: &git.Client{
2687 GhPath: "some/path/gh",
2688 GitPath: "some/path/git",
2689 },
2690 Finder: shared.NewMockFinder("feature", nil, nil),
2691 Remotes: func() (context.Remotes, error) {
2692 return context.Remotes{
2693 {
2694 Remote: &git.Remote{
2695 Name: "upstream",
2696 Resolved: "base",
2697 },
2698 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
NewMockConfigFunction · 0.92
NewMockFinderFunction · 0.92
NewFunction · 0.92
EqualMethod · 0.80
createRunFunction · 0.70

Tested by

no test coverage detected