|
|
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)
|
|
|
} |
...
|
...
|
|