query_result_test.go
1017 字节
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 k3cloud
import "testing"
func TestErrorResult(t *testing.T) {
jsonByte := []byte(`[[{"Result":{"ResponseStatus":{"ErrorCode":500,"IsSuccess":false,"Errors":[{"FieldName":null,"Message":"元数据中标识为FUseOrg的字段不存在","DIndex":0}],"SuccessEntitys":[],"SuccessMessages":[],"MsgCode":9}}}]]`)
result := newQueryResult(jsonByte, "")
if !result.IsError() {
t.Error("没有正确识别错误的消息数据")
return
}
m := result.ToMap()
if len(m) > 0 {
t.Error("解析了错误的数据")
return
}
e := result.Error()
if e == nil {
t.Error("没有正常的获得错误信息")
return
}
t.Logf("%v", result.Error())
}
func TestRightResult(t *testing.T) {
jsonByte := []byte(`[["xxx","abc",2345],["xxa","abc1",23457],["xxb","abc2",23458]]`)
result := newQueryResult(jsonByte, "name,desc,number")
if result.IsError() {
t.Error("数据解析失败")
return
}
m := result.ToMapString()
if len(m) == 0 {
t.Error("没有返回数据")
return
}
t.Logf("%v", m)
}