tokers commented on a change in pull request #1061:
URL: https://github.com/apache/apisix-dashboard/pull/1061#discussion_r545083312
##########
File path: api/internal/utils/utils.go
##########
@@ -94,3 +95,38 @@ func InterfaceToString(val interface{}) string {
str := fmt.Sprintf("%v", val)
return str
}
+
+func GenLabelMap(label string) map[string]string {
+ mp := make(map[string]string)
+
+ if label == "" {
+ return mp
+ }
+
+ labels := strings.Split(label, ",")
+ for _, l := range labels {
+ kv := strings.Split(l, ":")
+ if len(kv) == 2 {
+ mp[kv[0]] = kv[1]
+ } else if len(kv) == 1 {
+ mp[kv[0]] = ""
+ }
Review comment:
Log the malformed label, it's useful when you debug problems.
##########
File path: api/internal/handler/route/route_test.go
##########
@@ -797,6 +801,39 @@ func TestRoute(t *testing.T) {
dataPage = retPage.(*store.ListOutput)
assert.Equal(t, len(dataPage.Rows), 0)
+ //list search label not match
+ listInput5 := &ListInput{}
+ reqBody = `{"page_size": 1, "page": 1, "label":"l3"}`
+ err = json.Unmarshal([]byte(reqBody), listInput5)
+ assert.Nil(t, err)
+ ctx.SetInput(listInput5)
+ retPage, err = handler.List(ctx)
+ assert.Nil(t, err)
+ dataPage = retPage.(*store.ListOutput)
+ assert.Equal(t, len(dataPage.Rows), 0)
+
+ //list search label match
+ listInput6 := &ListInput{}
+ reqBody = `{"page_size": 1, "page": 1, "label":"l1"}`
+ err = json.Unmarshal([]byte(reqBody), listInput6)
+ assert.Nil(t, err)
+ ctx.SetInput(listInput6)
+ retPage, err = handler.List(ctx)
+ assert.Nil(t, err)
+ dataPage = retPage.(*store.ListOutput)
+ assert.Equal(t, len(dataPage.Rows), 1)
+
+ //list search label match
+ listInput7 := &ListInput{}
Review comment:
Should add another case that label specifies key and value, but value
doesn't not matched with existing one.
----------------------------------------------------------------
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]