api-client-go/errs/error_test.go

46 lines
884 B
Go
Raw Normal View History

2018-10-18 18:21:07 +03:00
package errs
import (
"testing"
)
func TestFailure_ApiErrorsSlice(t *testing.T) {
var err = Failure{}
b := []byte(`{"success": false, "errorMsg": "Failed to activate module", "errors": ["Your account has insufficient funds to activate integration module"]}`)
resp, e := ErrorResponse(b)
err.RuntimeErr = e
err.ApiErr = resp.ErrorMsg
if resp.Errors != nil {
err.ApiErrs = resp.Errors
}
f, ok := resp.Errors.([]interface{})
if !ok {
t.Errorf("%+v", f)
}
}
func TestFailure_ApiErrorsMap(t *testing.T) {
var err = Failure{}
b := []byte(`{"success": false, "errorMsg": "Failed to activate module", "errors": {"id": "ID must be an integer"}}`)
resp, e := ErrorResponse(b)
err.RuntimeErr = e
err.ApiErr = resp.ErrorMsg
if resp.Errors != nil {
err.ApiErrs = resp.Errors
}
f, ok := resp.Errors.(map[string]interface{})
if !ok {
t.Errorf("%+v", f)
}
}