Skip to content

Commit

Permalink
Add error test
Browse files Browse the repository at this point in the history
  • Loading branch information
osamingo committed Jun 29, 2017
1 parent 6c6df45 commit 6af753b
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions error_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package gaurun

import (
"bytes"
"io/ioutil"
"net/http"
"testing"
)

func TestNewError(t *testing.T) {
tbl := []struct {
Response *http.Response
Expected string
}{
{
Response: &http.Response{
StatusCode: http.StatusBadRequest,
Body: ioutil.NopCloser(bytes.NewBufferString("{")),
},
Expected: "gaurun: failed to decode http response: unexpected EOF",
},
{
Response: &http.Response{
StatusCode: http.StatusBadRequest,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"message":"empty notification"}`)),
},
Expected: "gaurun: an error occurred - status_code = 400, response = {Message:empty notification}",
},
}
for i := range tbl {
err := NewError(tbl[i].Response)
if tbl[i].Expected != err.Error() {
t.Errorf("failed to test - expected = %s, actual = %s", tbl[i].Expected, err.Error())
}
}
}

0 comments on commit 6af753b

Please sign in to comment.