Merge pull request #669 from doi-t/add-pr-status-tests
Add unit tests for Closed and Merged states of the current branch
This commit is contained in:
commit
206844681b
3 changed files with 91 additions and 49 deletions
|
|
@ -156,33 +156,6 @@ func TestPRStatus_reviewsAndChecks(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPRStatus_closedMerged(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "blueberries")
|
||||
http := initFakeHTTP()
|
||||
http.StubRepoResponse("OWNER", "REPO")
|
||||
|
||||
jsonFile, _ := os.Open("../test/fixtures/prStatusClosedMerged.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)
|
||||
}
|
||||
|
||||
expected := []string{
|
||||
"- Checks passing - Changes requested",
|
||||
"- Closed",
|
||||
"- Merged",
|
||||
}
|
||||
|
||||
for _, line := range expected {
|
||||
if !strings.Contains(output.String(), line) {
|
||||
t.Errorf("output did not contain %q: %q", line, output.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPRStatus_currentBranch_showTheMostRecentPR(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "blueberries")
|
||||
http := initFakeHTTP()
|
||||
|
|
@ -215,6 +188,48 @@ func TestPRStatus_currentBranch_showTheMostRecentPR(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPRStatus_currentBranch_Closed(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "blueberries")
|
||||
http := initFakeHTTP()
|
||||
http.StubRepoResponse("OWNER", "REPO")
|
||||
|
||||
jsonFile, _ := os.Open("../test/fixtures/prStatusCurrentBranchClosed.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(`#8 Blueberries are a good fruit \[blueberries\] - Closed`)
|
||||
if !expectedLine.MatchString(output.String()) {
|
||||
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", expectedLine, output)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestPRStatus_currentBranch_Merged(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "blueberries")
|
||||
http := initFakeHTTP()
|
||||
http.StubRepoResponse("OWNER", "REPO")
|
||||
|
||||
jsonFile, _ := os.Open("../test/fixtures/prStatusCurrentBranchMerged.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(`#8 Blueberries are a good fruit \[blueberries\] - Merged`)
|
||||
if !expectedLine.MatchString(output.String()) {
|
||||
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", expectedLine, output)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestPRStatus_blankSlate(t *testing.T) {
|
||||
initBlankContext("OWNER/REPO", "blueberries")
|
||||
http := initFakeHTTP()
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"node": {
|
||||
"number": 8,
|
||||
"title": "Blueberries are a good fruit",
|
||||
"state": "OPEN",
|
||||
"state": "CLOSED",
|
||||
"url": "https://github.com/cli/cli/pull/8",
|
||||
"headRefName": "blueberries",
|
||||
"reviewDecision": "CHANGES_REQUESTED",
|
||||
|
|
@ -35,27 +35,8 @@
|
|||
}
|
||||
},
|
||||
"viewerCreated": {
|
||||
"totalCount": 1,
|
||||
"edges": [
|
||||
{
|
||||
"node": {
|
||||
"number": 10,
|
||||
"state": "CLOSED",
|
||||
"title": "Strawberries are not actually berries",
|
||||
"url": "https://github.com/cli/cli/pull/10",
|
||||
"headRefName": "strawberries"
|
||||
}
|
||||
},
|
||||
{
|
||||
"node": {
|
||||
"number": 9,
|
||||
"state": "MERGED",
|
||||
"title": "Bananas are berries",
|
||||
"url": "https://github.com/cli/cli/pull/9",
|
||||
"headRefName": "banananana"
|
||||
}
|
||||
}
|
||||
]
|
||||
"totalCount": 0,
|
||||
"edges": []
|
||||
},
|
||||
"reviewRequested": {
|
||||
"totalCount": 0,
|
||||
46
test/fixtures/prStatusCurrentBranchMerged.json
vendored
Normal file
46
test/fixtures/prStatusCurrentBranchMerged.json
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
{
|
||||
"data": {
|
||||
"repository": {
|
||||
"pullRequests": {
|
||||
"totalCount": 1,
|
||||
"edges": [
|
||||
{
|
||||
"node": {
|
||||
"number": 8,
|
||||
"title": "Blueberries are a good fruit",
|
||||
"state": "MERGED",
|
||||
"url": "https://github.com/cli/cli/pull/8",
|
||||
"headRefName": "blueberries",
|
||||
"reviewDecision": "CHANGES_REQUESTED",
|
||||
"commits": {
|
||||
"nodes": [
|
||||
{
|
||||
"commit": {
|
||||
"statusCheckRollup": {
|
||||
"contexts": {
|
||||
"nodes": [
|
||||
{
|
||||
"state": "SUCCESS"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"viewerCreated": {
|
||||
"totalCount": 0,
|
||||
"edges": []
|
||||
},
|
||||
"reviewRequested": {
|
||||
"totalCount": 0,
|
||||
"edges": []
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue