-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} | ||
} |