liuxiran commented on a change in pull request #1812:
URL: https://github.com/apache/apisix-dashboard/pull/1812#discussion_r619734507
##########
File path: api/internal/core/entity/format_test.go
##########
@@ -101,3 +101,53 @@ func TestNodesFormat_Map(t *testing.T) {
assert.Contains(t, jsonStr, `"port":8080`)
assert.Contains(t, jsonStr, `"host":"127.0.0.1"`)
}
+
+func TestNodesFormat_empty_struct(t *testing.T) {
+ // route data saved in ETCD
+ routeStr := `{
+ "uris": ["/*"],
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": []
+ }
+ }`
+
+ // bind struct
+ var route Route
+ err := json.Unmarshal([]byte(routeStr), &route)
+ assert.Nil(t, err)
+
+ // nodes format
+ nodes := NodesFormat(route.Upstream.Nodes)
+
+ // json encode for client
+ res, err := json.Marshal(nodes)
+ assert.Nil(t, err)
+ jsonStr := string(res)
+ assert.Contains(t, jsonStr, `[]`)
+}
+
+func TestNodesFormat_empty_map(t *testing.T) {
+ // route data saved in ETCD
+ routeStr := `{
+ "uris": ["/*"],
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {}
+ }
+ }`
+
+ // bind struct
+ var route Route
+ err := json.Unmarshal([]byte(routeStr), &route)
+ assert.Nil(t, err)
+
+ // nodes format
+ nodes := NodesFormat(route.Upstream.Nodes)
+
+ // json encode for client
+ res, err := json.Marshal(nodes)
+ assert.Nil(t, err)
+ jsonStr := string(res)
+ assert.Contains(t, jsonStr, `[]`)
+}
Review comment:
done.
--
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]