forked from yankeguo/zhipu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_test.go
38 lines (33 loc) · 962 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
package zhipu
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
)
func TestAPIError(t *testing.T) {
err := APIError{
Code: "code",
Message: "message",
}
require.Equal(t, "message", err.Error())
require.Equal(t, "code", GetAPIErrorCode(err))
require.Equal(t, "message", GetAPIErrorMessage(err))
}
func TestAPIErrorResponse(t *testing.T) {
err := APIErrorResponse{
APIError: APIError{
Code: "code",
Message: "message",
},
}
require.Equal(t, "message", err.Error())
require.Equal(t, "code", GetAPIErrorCode(err))
require.Equal(t, "message", GetAPIErrorMessage(err))
}
func TestAPIErrorResponseFromDoc(t *testing.T) {
var res APIErrorResponse
err := json.Unmarshal([]byte(`{"error":{"code":"1002","message":"Authorization Token非法,请确认Authorization Token正确传递。"}}`), &res)
require.NoError(t, err)
require.Equal(t, "1002", res.Code)
require.Equal(t, "1002", GetAPIErrorCode(res))
}