-
Notifications
You must be signed in to change notification settings - Fork 4
/
error_test.go
36 lines (34 loc) · 865 Bytes
/
error_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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())
}
}
}