You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ch...@apache.org on 2020/12/01 09:20:54 UTC

[apisix-dashboard] branch master updated: fix: upstream node can't display when the node's weight is set to 0 (#934)

This is an automated email from the ASF dual-hosted git repository.

chenjunxu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new d42d2e8  fix: upstream node can't display when the node's weight is set to 0 (#934)
d42d2e8 is described below

commit d42d2e8fdf009a2493115e18e60624899fa6bc60
Author: nic-chen <33...@users.noreply.github.com>
AuthorDate: Tue Dec 1 17:20:48 2020 +0800

    fix: upstream node can't display when the node's weight is set to 0 (#934)
---
 api/internal/core/entity/format.go      |  3 ++-
 api/internal/core/entity/format_test.go | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/api/internal/core/entity/format.go b/api/internal/core/entity/format.go
index a1384b4..c4bb9f9 100644
--- a/api/internal/core/entity/format.go
+++ b/api/internal/core/entity/format.go
@@ -72,8 +72,9 @@ func NodesFormat(obj interface{}) interface{} {
 		return nodes
 	case []*Node:
 		log.Infof("nodes type: %v", objType)
-		return nodes
+		return obj
 	case []interface{}:
+		log.Infof("nodes type []interface{}: %v", objType)
 		list := obj.([]interface{})
 		for _, v := range list {
 			val := v.(map[string]interface{})
diff --git a/api/internal/core/entity/format_test.go b/api/internal/core/entity/format_test.go
index ab63232..7ca9d4c 100644
--- a/api/internal/core/entity/format_test.go
+++ b/api/internal/core/entity/format_test.go
@@ -54,6 +54,27 @@ func TestNodesFormat(t *testing.T) {
 	assert.Contains(t, jsonStr, `"host":"127.0.0.1"`)
 }
 
+func TestNodesFormat_struct(t *testing.T) {
+	// route data saved in ETCD
+	var route Route
+	route.Uris = []string{"/*"}
+	route.Upstream = &UpstreamDef{}
+	route.Upstream.Type = "roundrobin"
+	var nodes = []*Node{{Host: "127.0.0.1", Port: 80, Weight: 0}}
+	route.Upstream.Nodes = nodes
+
+	// nodes format
+	formattedNodes := NodesFormat(route.Upstream.Nodes)
+
+	// json encode for client
+	res, err := json.Marshal(formattedNodes)
+	assert.Nil(t, err)
+	jsonStr := string(res)
+	assert.Contains(t, jsonStr, `"weight":0`)
+	assert.Contains(t, jsonStr, `"port":80`)
+	assert.Contains(t, jsonStr, `"host":"127.0.0.1"`)
+}
+
 func TestNodesFormat_Map(t *testing.T) {
 	// route data saved in ETCD
 	routeStr := `{