mirror of
https://github.com/retailcrm/api-client-go.git
synced 2025-04-03 13:13:37 +03:00
fixed review
This commit is contained in:
parent
a09de71b1b
commit
e23eb5bfff
2 changed files with 16 additions and 4 deletions
|
@ -8,9 +8,15 @@ import (
|
|||
)
|
||||
|
||||
func TestFailure_ApiErrorsSlice(t *testing.T) {
|
||||
b := []byte(`{"success": false, "errorMsg": "Failed to activate module", "errors": ["Your account has insufficient funds to activate integration module"]}`)
|
||||
b := []byte(`{"success": false,
|
||||
"errorMsg": "Failed to activate module",
|
||||
"errors": [
|
||||
"Your account has insufficient funds to activate integration module",
|
||||
"Test error"
|
||||
]}`)
|
||||
expected := APIErrorsList{
|
||||
"0": "Your account has insufficient funds to activate integration module",
|
||||
"1": "Test error",
|
||||
}
|
||||
|
||||
var expEr *APIError
|
||||
|
@ -26,9 +32,13 @@ func TestFailure_ApiErrorsSlice(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFailure_ApiErrorsMap(t *testing.T) {
|
||||
b := []byte(`{"success": false, "errorMsg": "Failed to activate module", "errors": {"id": "ID must be an integer"}}`)
|
||||
b := []byte(`{"success": false,
|
||||
"errorMsg": "Failed to activate module",
|
||||
"errors": {"id": "ID must be an integer", "test": "Test error"}}`,
|
||||
)
|
||||
expected := APIErrorsList{
|
||||
"id": "ID must be an integer",
|
||||
"id": "ID must be an integer",
|
||||
"test": "Test error",
|
||||
}
|
||||
|
||||
var expEr *APIError
|
||||
|
|
|
@ -12,17 +12,19 @@ func (t Tag) MarshalJSON() ([]byte, error) {
|
|||
|
||||
func (a *APIErrorsList) UnmarshalJSON(data []byte) error {
|
||||
var i interface{}
|
||||
var m map[string]string
|
||||
if err := json.Unmarshal(data, &i); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m := make(map[string]string)
|
||||
switch e := i.(type) {
|
||||
case map[string]interface{}:
|
||||
m = make(map[string]string, len(e))
|
||||
for idx, val := range e {
|
||||
m[idx] = fmt.Sprint(val)
|
||||
}
|
||||
case []interface{}:
|
||||
m = make(map[string]string, len(e))
|
||||
for idx, val := range e {
|
||||
m[strconv.Itoa(idx)] = fmt.Sprint(val)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue