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 2020/12/30 12:31:13 UTC

[GitHub] [apisix-dashboard] juzhiyuan commented on a change in pull request #1151: fix: search labels with the same key

juzhiyuan commented on a change in pull request #1151:
URL: https://github.com/apache/apisix-dashboard/pull/1151#discussion_r550177929



##########
File path: api/internal/handler/label/label.go
##########
@@ -78,15 +78,18 @@ type ListInput struct {
 	Label string `auto_read:"label,query"`
 }
 
-func subsetOf(reqLabels, labels map[string]string) map[string]string {
+func subsetOf(reqLabels map[string]struct{}, labels map[string]string) map[string]string {
 	if len(reqLabels) == 0 {
 		return labels
 	}
 
 	var res = make(map[string]string)
 	for k, v := range labels {
-		l, exist := reqLabels[k]
-		if exist && ((l == "") || v == l) {
+		if _, exist := reqLabels[k]; exist {
+			res[k] = v
+		}
+
+		if _, exist := reqLabels[k+":"+v]; exist {

Review comment:
       `[k+":"+v]` formmated?

##########
File path: api/test/e2e/label_test.go
##########
@@ -200,6 +200,16 @@ func TestLabel(t *testing.T) {
 			ExpectStatus: http.StatusOK,
 			ExpectBody:   "{\"build\":\"16\"},{\"build\":\"17\"}",
 		},
+		{
+			Desc:         "get labels with the same key (key = build)",
+			Object:       ManagerApiExpect(t),
+			Method:       http.MethodGet,
+			Headers:      map[string]string{"Authorization": token},
+			Query:        "label=build:16,build:17",
+			Path:         "/apisix/admin/labels/all",

Review comment:
       🤔 What will happen if calling `/labels` only?

##########
File path: api/test/e2e/route_with_management_fileds_test.go
##########
@@ -333,6 +333,17 @@ func TestRoute_search_by_label(t *testing.T) {
 			ExpectBody:   "\"total_size\":2",
 			Sleep:        sleepTime,
 		},
+		{
+			Desc:         "search the route by label (combination)",
+			Object:       ManagerApiExpect(t),
+			Path:         "/apisix/admin/routes",
+			Query:        "label=build:16,build:17",
+			Method:       http.MethodGet,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "\"total_size\":2",

Review comment:
       just to confirm, is this all contents in response?




----------------------------------------------------------------
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