You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by zh...@apache.org on 2022/03/02 01:01:46 UTC
[apisix-ingress-controller] branch master updated: fix json unmarshal error when list plguins (#888)
This is an automated email from the ASF dual-hosted git repository.
zhangjintao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git
The following commit(s) were added to refs/heads/master by this push:
new cc9b6be fix json unmarshal error when list plguins (#888)
cc9b6be is described below
commit cc9b6be606b4d41267064c45e7ef1e9f5a6d8e47
Author: cmssczy <ca...@cmss.chinamobile.com>
AuthorDate: Wed Mar 2 09:01:39 2022 +0800
fix json unmarshal error when list plguins (#888)
---
pkg/apisix/cluster.go | 9 +++++++--
pkg/apisix/plugin_test.go | 10 +++++++++-
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/pkg/apisix/cluster.go b/pkg/apisix/cluster.go
index 4a5dbd7..8b7a938 100644
--- a/pkg/apisix/cluster.go
+++ b/pkg/apisix/cluster.go
@@ -750,10 +750,15 @@ func (c *cluster) getList(ctx context.Context, url, resource string) ([]string,
return nil, err
}
- var listResponse []string
+ var listResponse map[string]interface{}
dec := json.NewDecoder(resp.Body)
if err := dec.Decode(&listResponse); err != nil {
return nil, err
}
- return listResponse, nil
+ res := make([]string, 0, len(listResponse))
+
+ for name := range listResponse {
+ res = append(res, name)
+ }
+ return res, nil
}
diff --git a/pkg/apisix/plugin_test.go b/pkg/apisix/plugin_test.go
index dd64201..2d5c15a 100644
--- a/pkg/apisix/plugin_test.go
+++ b/pkg/apisix/plugin_test.go
@@ -19,6 +19,7 @@ import (
"encoding/json"
"net/http"
"net/url"
+ "sort"
"strings"
"testing"
@@ -46,8 +47,13 @@ func (srv *fakeAPISIXPluginSrv) ServeHTTP(w http.ResponseWriter, r *http.Request
return
}
+ fakePluginsResp := make(map[string]interface{}, len(srv.plugins))
+ for _, fp := range srv.plugins {
+ fakePluginsResp[fp] = struct{}{}
+ }
+
if r.Method == http.MethodGet {
- data, _ := json.Marshal(srv.plugins)
+ data, _ := json.Marshal(fakePluginsResp)
_, _ = w.Write(data)
w.WriteHeader(http.StatusOK)
return
@@ -101,6 +107,8 @@ func TestPluginClient(t *testing.T) {
objs, err := cli.List(context.Background())
assert.Nil(t, err)
assert.Len(t, objs, len(fakePluginNames))
+ sort.Strings(fakePluginNames)
+ sort.Strings(objs)
for i := range fakePluginNames {
assert.Equal(t, fakePluginNames[i], objs[i])
}