You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/04/24 06:47:32 UTC

[GitHub] [apisix-dashboard] starsz commented on a change in pull request #1812: fix: can not configure upstream with no nodes

starsz commented on a change in pull request #1812:
URL: https://github.com/apache/apisix-dashboard/pull/1812#discussion_r619600269



##########
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:
       Need to test without the "nodes" field.




-- 
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:
users@infra.apache.org