Skip to content

Commit

Permalink
Merge branch 'develop' into 0701unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
tydhot authored Jul 5, 2021
2 parents 422c26d + ceb1f0e commit d432d61
Showing 1 changed file with 58 additions and 4 deletions.
62 changes: 58 additions & 4 deletions pkg/filter/response/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}
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")
}
f := responseFilter{}
result := f.newResponse(resp)
r := result.Data.(map[string]interface{})
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"])
}

0 comments on commit d432d61

Please sign in to comment.