cli/api/pull_request_test.go
Mislav Marohnić 7c731bc512 Avoid crash when parsing in-progress CheckRuns
Fixes `panic: unsupported status: ""`

This occurs when a CheckRun has status "IN_PROGRESS" (or any other than
"COMPLETED") and when its `conclusion` would be null. I previously
didn't account for this.

This adds support for parsing state of an in-progress CheckRun.
2019-11-19 09:42:59 +01:00

39 lines
806 B
Go

package api
import (
"encoding/json"
"testing"
)
func TestPullRequest_ChecksStatus(t *testing.T) {
pr := PullRequest{}
payload := `
{ "commits": { "nodes": [{ "commit": {
"statusCheckRollup": {
"contexts": {
"nodes": [
{ "state": "SUCCESS" },
{ "state": "PENDING" },
{ "state": "FAILURE" },
{ "status": "IN_PROGRESS",
"conclusion": null },
{ "status": "COMPLETED",
"conclusion": "SUCCESS" },
{ "status": "COMPLETED",
"conclusion": "FAILURE" },
{ "status": "COMPLETED",
"conclusion": "ACTION_REQUIRED" }
]
}
}
} }] } }
`
err := json.Unmarshal([]byte(payload), &pr)
eq(t, err, nil)
checks := pr.ChecksStatus()
eq(t, checks.Total, 7)
eq(t, checks.Pending, 2)
eq(t, checks.Failing, 3)
eq(t, checks.Passing, 2)
}