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

Function TestRemoteGuessing

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

Source from the content-addressed store, hash-verified

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