Skip to content

Commit 6af753b

Browse files
committed
Add error test
1 parent 6c6df45 commit 6af753b

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

error_test.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package gaurun
2+
3+
import (
4+
"bytes"
5+
"io/ioutil"
6+
"net/http"
7+
"testing"
8+
)
9+
10+
func TestNewError(t *testing.T) {
11+
tbl := []struct {
12+
Response *http.Response
13+
Expected string
14+
}{
15+
{
16+
Response: &http.Response{
17+
StatusCode: http.StatusBadRequest,
18+
Body: ioutil.NopCloser(bytes.NewBufferString("{")),
19+
},
20+
Expected: "gaurun: failed to decode http response: unexpected EOF",
21+
},
22+
{
23+
Response: &http.Response{
24+
StatusCode: http.StatusBadRequest,
25+
Body: ioutil.NopCloser(bytes.NewBufferString(`{"message":"empty notification"}`)),
26+
},
27+
Expected: "gaurun: an error occurred - status_code = 400, response = {Message:empty notification}",
28+
},
29+
}
30+
for i := range tbl {
31+
err := NewError(tbl[i].Response)
32+
if tbl[i].Expected != err.Error() {
33+
t.Errorf("failed to test - expected = %s, actual = %s", tbl[i].Expected, err.Error())
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)