Add simple merge test

This commit is contained in:
Corey Johnson 2020-05-05 11:35:19 -07:00
parent 39e6f412cb
commit 16ad382f4d

View file

@ -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())
}
}