- add unit test to test keyToRemove and keyToKeep in normal access.
This commit is contained in:
@@ -83,7 +83,6 @@ func getJDOperator() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getCurTimeStr() string {
|
func getCurTimeStr() string {
|
||||||
// return "2018-06-04 22:35:25"
|
|
||||||
return time.Now().Format("2006-01-02 15:04:05")
|
return time.Now().Format("2006-01-02 15:04:05")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,12 +235,12 @@ func (j JDAPI) accessJDQueryNoPage(apiStr string, jdParams map[string]string, ke
|
|||||||
if _, ok := jdResultInnerCodeOK[innerCode]; ok {
|
if _, ok := jdResultInnerCodeOK[innerCode]; ok {
|
||||||
for _, innerDataKey := range jdResultNoPageInnerDataKeys {
|
for _, innerDataKey := range jdResultNoPageInnerDataKeys {
|
||||||
if innerData, ok := data[innerDataKey]; ok {
|
if innerData, ok := data[innerDataKey]; ok {
|
||||||
return innerData, nil
|
return utils.DictKeysMan(innerData, keyToRemove, keyToKeep), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
panic("Can not find inner data")
|
panic("Can not find inner data")
|
||||||
} else {
|
} else {
|
||||||
return utils.DictKeysMan(jsonResult, keyToRemove, keyToKeep), ErrInnerCodeIsNotOk
|
return jsonResult, ErrInnerCodeIsNotOk
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ func TestAccessJDQuery(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAccessJDQueryNoPage(t *testing.T) {
|
func TestAccessJDQueryNoPage(t *testing.T) {
|
||||||
result, err := jdapi.accessJDQueryNoPage("address/allcities", nil, nil, nil)
|
result, err := jdapi.accessJDQueryNoPage("address/allcities", nil, []string{"yn"}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("accessJDQueryNoPage return error:%v", err)
|
t.Fatalf("accessJDQueryNoPage return error:%v", err)
|
||||||
}
|
}
|
||||||
@@ -47,21 +47,27 @@ func TestAccessJDQueryNoPage(t *testing.T) {
|
|||||||
if _, ok := oneCity["areaName"]; !ok {
|
if _, ok := oneCity["areaName"]; !ok {
|
||||||
t.Fatal("no areaName key")
|
t.Fatal("no areaName key")
|
||||||
}
|
}
|
||||||
|
if _, ok := oneCity["yn"]; ok {
|
||||||
|
t.Fatal("yn field havn't been removed")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccessJDQueryHavePage(t *testing.T) {
|
func TestAccessJDQueryHavePage(t *testing.T) {
|
||||||
result, err := jdapi.accessJDQueryHavePage("pms/querySkuInfos", nil, nil, nil, 1, 50, nil)
|
result, err := jdapi.accessJDQueryHavePage("pms/querySkuInfos", nil, nil, []string{"skuName", "skuId"}, 1, 50, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("accessJDQueryHavePage return error:%v", err)
|
t.Fatalf("accessJDQueryHavePage return error:%v", err)
|
||||||
}
|
}
|
||||||
skuInfo := result.([]interface{})
|
skuInfo := result.([]interface{})
|
||||||
if len(skuInfo) == 0 {
|
if len(skuInfo) == 0 {
|
||||||
t.Fatal("city info is empty")
|
t.Fatal("sku info is empty")
|
||||||
}
|
}
|
||||||
oneSku := skuInfo[0].(map[string]interface{})
|
oneSku := skuInfo[0].(map[string]interface{})
|
||||||
if _, ok := oneSku["skuName"]; !ok {
|
if _, ok := oneSku["skuName"]; !ok {
|
||||||
t.Fatal("no skuName key")
|
t.Fatal("no skuName key")
|
||||||
}
|
}
|
||||||
|
if _, ok := oneSku["outSkuId"]; ok {
|
||||||
|
t.Fatal("outSkuId key not removed")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenGetURL(t *testing.T) {
|
func TestGenGetURL(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user