Add a test for the current branch

This commit is contained in:
Toshiya Doi 2020-03-13 00:24:44 +09:00
parent 6db7e89abf
commit 3c4f006eff
2 changed files with 93 additions and 0 deletions

View file

@ -182,6 +182,38 @@ func TestPRStatus_closedMerged(t *testing.T) {
}
}
func TestPRStatus_currentBranch_showTheMostRecentPR(t *testing.T) {
initBlankContext("OWNER/REPO", "blueberries")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
jsonFile, _ := os.Open("../test/fixtures/prStatusCurrentBranch.json")
defer jsonFile.Close()
http.StubResponse(200, jsonFile)
output, err := RunCommand(prStatusCmd, "pr status")
if err != nil {
t.Errorf("error running command `pr status`: %v", err)
}
expectedLine := regexp.MustCompile(`#10 Blueberries are certainly a good fruit \[blueberries\]`)
if !expectedLine.MatchString(output.String()) {
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", expectedLine, output)
return
}
unexpectedLines := []*regexp.Regexp{
regexp.MustCompile(`#9 Blueberries are a good fruit \[blueberries\] - Merged`),
regexp.MustCompile(`#8 Blueberries are probably a good fruit \[blueberries\] - Closed`),
}
for _, r := range unexpectedLines {
if r.MatchString(output.String()) {
t.Errorf("output unexpectedly match regexp /%s/\n> output\n%s\n", r, output)
return
}
}
}
func TestPRStatus_blankSlate(t *testing.T) {
initBlankContext("OWNER/REPO", "blueberries")
http := initFakeHTTP()

View file

@ -0,0 +1,61 @@
{
"data": {
"repository": {
"pullRequests": {
"totalCount": 3,
"edges": [
{
"node": {
"number": 10,
"title": "Blueberries are certainly a good fruit",
"state": "OPEN",
"url": "https://github.com/PARENT/REPO/pull/10",
"headRefName": "blueberries",
"isDraft": false,
"headRepositoryOwner": {
"login": "OWNER/REPO"
},
"isCrossRepository": false
}
},
{
"node": {
"number": 9,
"title": "Blueberries are a good fruit",
"state": "MERGED",
"url": "https://github.com/PARENT/REPO/pull/9",
"headRefName": "blueberries",
"isDraft": false,
"headRepositoryOwner": {
"login": "OWNER/REPO"
},
"isCrossRepository": false
}
},
{
"node": {
"number": 8,
"title": "Blueberries are probably a good fruit",
"state": "CLOSED",
"url": "https://github.com/PARENT/REPO/pull/8",
"headRefName": "blueberries",
"isDraft": false,
"headRepositoryOwner": {
"login": "OWNER/REPO"
},
"isCrossRepository": false
}
}
]
}
},
"viewerCreated": {
"totalCount": 0,
"edges": []
},
"reviewRequested": {
"totalCount": 0,
"edges": []
}
}
}