nic-chen commented on a change in pull request #847:
URL: https://github.com/apache/apisix-dashboard/pull/847#discussion_r528512141
##########
File path: api/internal/core/entity/format_test.go
##########
@@ -23,19 +23,62 @@ import (
"github.com/stretchr/testify/assert"
)
-func TestConsumer(t *testing.T) {
- nodesStr := `{
- "127.0.0.1:8080": 1
- }`
- nodesMap := map[string]float64{}
- err := json.Unmarshal([]byte(nodesStr), &nodesMap)
+func TestNodesFormat(t *testing.T){
+ // route data saved in ETCD
+ routeStr := `{
+ "uris": ["/*"],
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": [{
+ "host": "127.0.0.1",
+ "port": 80,
+ "weight": 0
+ }]
+ }
+ }`
+
+ // bind struct
+ var route Route
+ err := json.Unmarshal([]byte(routeStr), &route)
assert.Nil(t, err)
- res := NodesFormat(nodesMap)
- nodes := res.([]*Node)
+ // nodes format
+ nodes := NodesFormat(route.Upstream.Nodes)
- assert.Equal(t, 1, len(nodes))
- assert.Equal(t, "127.0.0.1", nodes[0].Host)
- assert.Equal(t, 8080, nodes[0].Port)
- assert.Equal(t, 1, nodes[0].Weight)
+ // json encode for client
+ res, err := json.Marshal(nodes)
+ assert.Nil(t,err)
Review comment:
fixed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]