Enrich response.go's test case
@@ -25,17 +25,71 @@ import (
"github.com/stretchr/testify/assert"
)
-func TestNewDubboResponse(t *testing.T) {
+func TestNewDubboMapResponse(t *testing.T) {
+ slice := append(make([]string, 0), "read")
resp := map[string]interface{}{
"age": 18,
"iD": 0o001,
"name": "tc",
"time": nil,
+ "hobby": slice,
+ "father": map[string]interface{}{
+ "name": "bob",
+ },
}
- f := responseFilter{}
- result := f.newResponse(resp)
- r := result.Data.(map[string]interface{})
+ result, err := dealResp(resp, false)
+ if err != nil {
+ t.Error("failed to deal resp")
+ }
+ r := result.(map[string]interface{})
+ assert.Equal(t, 18, r["age"])
+ assert.Equal(t, 1, r["iD"])
+ assert.Equal(t, "tc", r["name"])
+ assert.Equal(t, "read", r["hobby"].([]string)[0])
+ assert.Equal(t, "bob", r["father"].(map[string]interface{})["name"])
+}
+
+func TestNewDubboMapHumpResponse(t *testing.T) {
+ slice := append(make([]string, 0), "readBook")
+ resp := map[string]interface{}{
+ "age": 18,
+ "iD": 0o001,
+ "name": "tc",
+ "time": nil,
+ "simpleHobby": slice,
+ "father": map[string]interface{}{
+ "name": "bob",
+ },
+ }
+ result, err := dealResp(resp, true)
+ if err != nil {
+ t.Error("failed to deal resp")
+ }
+ r := result.(map[string]interface{})
+ assert.Equal(t, 18, r["age"])
+ assert.Equal(t, 1, r["i_d"])
+ assert.Equal(t, "tc", r["name"])
+ assert.Equal(t, "readBook", r["simple_hobby"].([]interface{})[0])
+ assert.Equal(t, "bob", r["father"].(map[string]interface{})["name"])
+}
+
+func TestNewDubboSliceResponse(t *testing.T) {
+ resp := append(make([]map[string]interface{}, 0), map[string]interface{}{
+ "age": 18,
+ "iD": 0o001,
+ "name": "tc",
+ "time": nil,
+ "father": map[string]interface{}{
+ "name": "bob",
+ },
+ })
+ result, err := dealResp(resp, false)
+ if err != nil {
+ t.Error("failed to deal resp")
+ }
+ r := result.([]interface{})[0].(map[string]interface{})
assert.Equal(t, 18, r["age"])
assert.Equal(t, 1, r["iD"])
assert.Equal(t, "tc", r["name"])
+ assert.Equal(t, "bob", r["father"].(map[string]interface{})["name"])
}
