1
0
mirror of https://github.com/interviewstreet/go-jira.git synced 2025-06-14 23:45:03 +02:00

Fixed null pointer when no response is received

* JiraError can now handle nil responses
* Better error handling when the response is not JSON
This commit is contained in:
Bob Briski
2017-11-14 17:57:26 -08:00
parent 8686d2a5e0
commit 67d3f9b9ef
2 changed files with 38 additions and 1 deletions

View File

@ -29,6 +29,38 @@ func TestError_NewJiraError(t *testing.T) {
}
}
func TestError_NoResponse(t *testing.T) {
err := NewJiraError(nil, errors.New("Original http error"))
msg := err.Error()
if !strings.Contains(msg, "Original http error") {
t.Errorf("Expected the original error message: Got\n%s\n", msg)
}
if !strings.Contains(msg, "No response") {
t.Errorf("Expected the 'No response' error message: Got\n%s\n", msg)
}
}
func TestError_NoJSON(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `<html>Not JSON</html>`)
})
req, _ := testClient.NewRequest("GET", "/", nil)
resp, _ := testClient.Do(req, nil)
err := NewJiraError(resp, errors.New("Original http error"))
msg := err.Error()
if !strings.Contains(msg, "Could not parse JSON") {
t.Errorf("Expected the 'Could not parse JSON' error message: Got\n%s\n", msg)
}
}
func TestError_NilOriginalMessage(t *testing.T) {
defer func() {
if r := recover(); r != nil {