X Tutup
Skip to content

Commit 6c49614

Browse files
committed
Fix tests
1 parent 7a614ce commit 6c49614

File tree

4 files changed

+45
-18
lines changed

4 files changed

+45
-18
lines changed

api/client_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package api
22

33
import (
44
"bytes"
5-
"fmt"
65
"io/ioutil"
76
"reflect"
87
"testing"
@@ -47,5 +46,7 @@ func TestGraphQLError(t *testing.T) {
4746
response := struct{}{}
4847
http.StubResponse(200, bytes.NewBufferString(`{"errors":[{"message":"OH NO"}]}`))
4948
err := client.GraphQL("", nil, &response)
50-
eq(t, err, fmt.Errorf("graphql error: 'OH NO'"))
49+
if err == nil || err.Error() != "graphql error: 'OH NO'" {
50+
t.Fatalf("got %q", err.Error())
51+
}
5152
}

api/queries_pr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ func PullRequestForBranch(client *Client, ghRepo Repo, branch string) (*PullRequ
404404
}
405405

406406
// CreatePullRequest creates a pull request in a GitHub repository
407-
func CreatePullRequest(client *Client, repo Repository, params map[string]interface{}) (*PullRequest, error) {
407+
func CreatePullRequest(client *Client, repo *Repository, params map[string]interface{}) (*PullRequest, error) {
408408
query := `
409409
mutation CreatePullRequest($input: CreatePullRequestInput!) {
410410
createPullRequest(input: $input) {

command/pr_create.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ func prCreate(cmd *cobra.Command, _ []string) error {
6161
return fmt.Errorf("must be on a branch named differently than %q", baseBranch)
6262
}
6363

64-
fmt.Fprintf(colorableErr(cmd), "\nCreating pull request for %s into %s in %s/%s\n\n", utils.Cyan(headBranch), utils.Cyan(baseBranch), baseRepo.RepoOwner(), baseRepo.RepoName())
65-
6664
headRemote, err := repoContext.RemoteForRepo(headRepo)
6765
if err != nil {
6866
return errors.Wrap(err, "")
@@ -86,6 +84,12 @@ func prCreate(cmd *cobra.Command, _ []string) error {
8684
return utils.OpenInBrowser(openURL)
8785
}
8886

87+
fmt.Fprintf(colorableErr(cmd), "\nCreating pull request for %s into %s in %s/%s\n\n",
88+
utils.Cyan(headBranch),
89+
utils.Cyan(baseBranch),
90+
baseRepo.RepoOwner(),
91+
baseRepo.RepoName())
92+
8993
title, err := cmd.Flags().GetString("title")
9094
if err != nil {
9195
return errors.Wrap(err, "could not parse title")
@@ -140,8 +144,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
140144
"headRefName": headBranch,
141145
}
142146

143-
repo := api.Repository{}
144-
pr, err := api.CreatePullRequest(client, repo, params)
147+
pr, err := api.CreatePullRequest(client, baseRepo, params)
145148
if err != nil {
146149
return errors.Wrap(err, "failed to create pull request")
147150
}
@@ -261,7 +264,7 @@ func (r resolvedRemotes) BaseRepo() (*api.Repository, error) {
261264
func (r resolvedRemotes) HeadRepo() (*api.Repository, error) {
262265
for _, repo := range r.network.Repositories {
263266
if repo != nil && repo.ViewerCanPush() {
264-
return repo.Parent, nil
267+
return repo, nil
265268
}
266269
}
267270
return nil, errors.New("none of the repositories have push access")

command/pr_create_test.go

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,15 @@ func TestPRCreate(t *testing.T) {
5252
http := initFakeHTTP()
5353

5454
http.StubResponse(200, bytes.NewBufferString(`
55-
{ "data": { "repository": {
56-
"id": "REPOID"
55+
{ "data": { "repo_000": {
56+
"id": "REPOID",
57+
"name": "REPO",
58+
"owner": {"login": "OWNER"},
59+
"defaultBranchRef": {
60+
"name": "master",
61+
"target": {"oid": "deadbeef"}
62+
},
63+
"viewerPermission": "WRITE"
5764
} } }
5865
`))
5966
http.StubResponse(200, bytes.NewBufferString(`
@@ -103,7 +110,20 @@ func TestPRCreate_web(t *testing.T) {
103110
initContext = func() context.Context {
104111
return ctx
105112
}
106-
initFakeHTTP()
113+
http := initFakeHTTP()
114+
115+
http.StubResponse(200, bytes.NewBufferString(`
116+
{ "data": { "repo_000": {
117+
"id": "REPOID",
118+
"name": "REPO",
119+
"owner": {"login": "OWNER"},
120+
"defaultBranchRef": {
121+
"name": "master",
122+
"target": {"oid": "deadbeef"}
123+
},
124+
"viewerPermission": "WRITE"
125+
} } }
126+
`))
107127

108128
ranCommands := [][]string{}
109129
restoreCmd := utils.SetPrepareCmd(func(cmd *exec.Cmd) utils.Runnable {
@@ -116,11 +136,7 @@ func TestPRCreate_web(t *testing.T) {
116136
eq(t, err, nil)
117137

118138
eq(t, output.String(), "")
119-
eq(t, output.Stderr(), `
120-
Creating pull request for feature into master in OWNER/REPO
121-
122-
Opening https://github.com/OWNER/REPO/pull/feature in your browser.
123-
`)
139+
eq(t, output.Stderr(), "Opening https://github.com/OWNER/REPO/pull/feature in your browser.\n")
124140

125141
eq(t, len(ranCommands), 3)
126142
eq(t, strings.Join(ranCommands[1], " "), "git push --set-upstream origin HEAD:feature")
@@ -139,8 +155,15 @@ func TestPRCreate_ReportsUncommittedChanges(t *testing.T) {
139155
http := initFakeHTTP()
140156

141157
http.StubResponse(200, bytes.NewBufferString(`
142-
{ "data": { "repository": {
143-
"id": "REPOID"
158+
{ "data": { "repo_000": {
159+
"id": "REPOID",
160+
"name": "REPO",
161+
"owner": {"login": "OWNER"},
162+
"defaultBranchRef": {
163+
"name": "master",
164+
"target": {"oid": "deadbeef"}
165+
},
166+
"viewerPermission": "WRITE"
144167
} } }
145168
`))
146169
http.StubResponse(200, bytes.NewBufferString(`

0 commit comments

Comments
 (0)
X Tutup