diff --git a/command/pr_test.go b/command/pr_test.go index 0aff5e14a..86d2829d2 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -3,6 +3,7 @@ package command import ( "bytes" "encoding/json" + "io" "io/ioutil" "os" "os/exec" @@ -938,5 +939,39 @@ func TestPRReopen_alreadyMerged(t *testing.T) { if !r.MatchString(err.Error()) { t.Fatalf("output did not match regexp /%s/\n> output\n%q\n", r, output.Stderr()) } - +} + +type stubResponse struct { + ResponseCode int + ResponseBody io.Reader +} + +func initWithStubs(stubs ...stubResponse) { + initBlankContext("", "OWNER/REPO", "master") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + for _, s := range stubs { + http.StubResponse(s.ResponseCode, s.ResponseBody) + } +} + +func TestPrMerge(t *testing.T) { + initWithStubs( + stubResponse{200, bytes.NewBufferString(`{ "data": { "repository": { + "pullRequest": { "number": 1, "closed": false, "state": "OPEN"} + } } }`)}, + stubResponse{200, bytes.NewBufferString(`{"id": "THE-ID"}`)}, + ) + + output, err := RunCommand("pr merge 1") + if err != nil { + t.Fatalf("error running command `pr merge`: %v", err) + } + + r := regexp.MustCompile(`Merged pull request #1`) + + if !r.MatchString(output.Stderr()) { + t.Fatalf("output did not match regexp /%s/\n> output\n%q\n", r, output.Stderr()) + } }