From 3d21a33bac0056d05fbaf604a8aa94cc17c72f61 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 6 May 2020 11:47:43 -0700 Subject: [PATCH] update test --- command/pr_test.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/command/pr_test.go b/command/pr_test.go index 6b5be7eb6..4bbba2eae 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -946,8 +946,8 @@ type stubResponse struct { ResponseBody io.Reader } -func initWithStubs(stubs ...stubResponse) { - initBlankContext("", "OWNER/REPO", "master") +func initWithStubs(branch string, stubs ...stubResponse) { + initBlankContext("", "OWNER/REPO", branch) http := initFakeHTTP() http.StubRepoResponse("OWNER", "REPO") @@ -957,7 +957,7 @@ func initWithStubs(stubs ...stubResponse) { } func TestPrMerge(t *testing.T) { - initWithStubs( + initWithStubs("master", stubResponse{200, bytes.NewBufferString(`{ "data": { "repository": { "pullRequest": { "number": 1, "closed": false, "state": "OPEN"} } } }`)}, @@ -977,10 +977,16 @@ func TestPrMerge(t *testing.T) { } func TestPrMerge_noPrNumberGiven(t *testing.T) { - initWithStubs( - stubResponse{200, bytes.NewBufferString(`{ "data": { "repository": { - "pullRequest": { "number": 100, "closed": false, "state": "OPEN"} - } } }`)}, + cs, cmdTeardown := test.InitCmdStubber() + defer cmdTeardown() + + cs.Stub("branch.blueberries.remote origin\nbranch.blueberries.merge refs/heads/blueberries") // git config --get-regexp ^branch\.master\.(remote|merge) + + jsonFile, _ := os.Open("../test/fixtures/prViewPreviewWithMetadataByBranch.json") + defer jsonFile.Close() + + initWithStubs("blueberries", + stubResponse{200, jsonFile}, stubResponse{200, bytes.NewBufferString(`{"id": "THE-ID"}`)}, ) @@ -989,7 +995,7 @@ func TestPrMerge_noPrNumberGiven(t *testing.T) { t.Fatalf("error running command `pr merge`: %v", err) } - r := regexp.MustCompile(`Merged pull request #100`) + r := regexp.MustCompile(`Merged pull request #10`) if !r.MatchString(output.Stderr()) { t.Fatalf("output did not match regexp /%s/\n> output\n%q\n", r, output.Stderr()) @@ -997,7 +1003,7 @@ func TestPrMerge_noPrNumberGiven(t *testing.T) { } func TestPrMerge_rebase(t *testing.T) { - initWithStubs( + initWithStubs("master", stubResponse{200, bytes.NewBufferString(`{ "data": { "repository": { "pullRequest": { "number": 2, "closed": false, "state": "OPEN"} } } }`)}, @@ -1017,7 +1023,7 @@ func TestPrMerge_rebase(t *testing.T) { } func TestPrMerge_squash(t *testing.T) { - initWithStubs( + initWithStubs("master", stubResponse{200, bytes.NewBufferString(`{ "data": { "repository": { "pullRequest": { "number": 3, "closed": false, "state": "OPEN"} } } }`)}, @@ -1037,7 +1043,7 @@ func TestPrMerge_squash(t *testing.T) { } func TestPrMerge_alreadyMerged(t *testing.T) { - initWithStubs( + initWithStubs("master", stubResponse{200, bytes.NewBufferString(`{ "data": { "repository": { "pullRequest": { "number": 4, "closed": true, "state": "MERGED"} } } }`)},