-
Notifications
You must be signed in to change notification settings - Fork 12
/
error_test.go
43 lines (30 loc) · 913 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
37
38
39
40
41
42
43
package synapse
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
var errorData map[string]interface{}
/********** METHODS **********/
func init() {
data, err := readFile("error_responses")
if err != nil {
panic(err)
}
errorData = data
}
/********** TESTS **********/
func Test_HandleHTTPError(t *testing.T) {
assert := assert.New(t)
for k := range errorData {
testErrRes, _ := json.Marshal(errorData[k])
testErr := handleHTTPError(testErrRes)
errData := errorData[k].(map[string]interface{})
httpCode := errData["http_code"].(string)
errCode := errData["error_code"].(string)
msg := errData["error"].(map[string]interface{})["en"].(string)
responseMsg := "http_code " + httpCode + " error_code " + errCode + " " + msg
// error message should be an error and print error code plus original API message
assert.EqualError(testErr, responseMsg)
}
}