You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ju...@apache.org on 2021/01/07 01:37:43 UTC

[apisix-dashboard] branch v2.3 updated: fix(be): search by status on the route list page is invalid (#1207) (#1224)

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

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


The following commit(s) were added to refs/heads/v2.3 by this push:
     new d39951b  fix(be): search by status on the route list page is invalid (#1207) (#1224)
d39951b is described below

commit d39951b361ebabd574adcfa6c3ba54f8bdbbeee4
Author: Joey <ma...@gmail.com>
AuthorDate: Thu Jan 7 09:37:36 2021 +0800

    fix(be): search by status on the route list page is invalid (#1207) (#1224)
    
    * fix search by status on the route list page is invalid
    
    * Fix test cases and references
    
    * Update route.go
    
    * Update route.go
    
    * Format error repair
    
    * use strconv.Itoa Method conversion uint8
    
    * chore: use the correct API version (#1215)
    
    Co-authored-by: litesun <su...@apache.org>
    
    fix: online debug body params support content-type x-www-form-urlencoded (#1201)
    
    * fix: online debug body params support content-type x-www-form-urlencoded
    
    * fix: body code mirror support different mode
    
    * fix: use enum instead of real string
    
    * fix: lint error
    
    Co-authored-by: 琚致远 <ju...@apache.org>
    
    feat: add tips when plugin type is auth and schemaType is not consumer (#1219)
    
    Co-authored-by: 琚致远 <ju...@apache.org>
    
    * Fix indent format problem
    
    Co-authored-by: 琚致远 <ju...@apache.org>
    
    Co-authored-by: JinChen <36...@users.noreply.github.com>
    Co-authored-by: 琚致远 <ju...@apache.org>
---
 api/internal/handler/route/route.go      | 12 ++++++--
 api/internal/handler/route/route_test.go | 49 ++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 3 deletions(-)

diff --git a/api/internal/handler/route/route.go b/api/internal/handler/route/route.go
index 59dc6ce..89083ed 100644
--- a/api/internal/handler/route/route.go
+++ b/api/internal/handler/route/route.go
@@ -23,6 +23,7 @@ import (
 	"os"
 	"path/filepath"
 	"reflect"
+	"strconv"
 	"strings"
 
 	"github.com/gin-gonic/gin"
@@ -178,9 +179,10 @@ func (h *Handler) Get(c droplet.Context) (interface{}, error) {
 }
 
 type ListInput struct {
-	Name  string `auto_read:"name,query"`
-	URI   string `auto_read:"uri,query"`
-	Label string `auto_read:"label,query"`
+	Name   string `auto_read:"name,query"`
+	URI    string `auto_read:"uri,query"`
+	Label  string `auto_read:"label,query"`
+	Status string `auto_read:"status,query"`
 	store.Pagination
 }
 
@@ -219,6 +221,10 @@ func (h *Handler) List(c droplet.Context) (interface{}, error) {
 				return false
 			}
 
+			if input.Status != "" && strconv.Itoa(int(obj.(*entity.Route).Status)) != input.Status {
+				return false
+			}
+
 			return true
 		},
 		Format: func(obj interface{}) interface{} {
diff --git a/api/internal/handler/route/route_test.go b/api/internal/handler/route/route_test.go
index f84fc90..4618755 100644
--- a/api/internal/handler/route/route_test.go
+++ b/api/internal/handler/route/route_test.go
@@ -59,6 +59,7 @@ func TestRoute(t *testing.T) {
 	  "vars": [],
 	  "remote_addrs": ["127.0.0.0/8"],
 	  "methods": ["PUT", "GET"],
+	  "status": 1,
 	  "upstream": {
 	      "type": "roundrobin",
 	      "nodes": [{
@@ -415,6 +416,7 @@ func TestRoute(t *testing.T) {
 	  "hosts": ["foo.com", "*.bar.com"],
 	  "remote_addrs": ["127.0.0.0/8"],
 	  "methods": ["PUT", "GET"],
+	  "status": 1,
 	  "labels": {
 	      "l1": "v1",
 	      "l2": "v2"
@@ -925,6 +927,42 @@ func TestRoute(t *testing.T) {
 	dataPage = retPage.(*store.ListOutput)
 	assert.Equal(t, len(dataPage.Rows), 0)
 
+	// list search and status match
+	listInput = &ListInput{}
+	reqBody = `{"page_size": 1, "page": 1, "status": "1"}`
+	err = json.Unmarshal([]byte(reqBody), listInput)
+	assert.Nil(t, err)
+	ctx.SetInput(listInput)
+	retPage, err = handler.List(ctx)
+	assert.Nil(t, err)
+	dataPage = retPage.(*store.ListOutput)
+	assert.Equal(t, len(dataPage.Rows), 1)
+
+        //sleep
+	time.Sleep(time.Duration(100) * time.Millisecond)
+
+	// list search and status not match
+	listInput = &ListInput{}
+	reqBody = `{"page_size": 1, "page": 1, "name": "a", "status": "0"}`
+	err = json.Unmarshal([]byte(reqBody), listInput)
+	assert.Nil(t, err)
+	ctx.SetInput(listInput)
+	retPage, err = handler.List(ctx)
+	assert.Nil(t, err)
+	dataPage = retPage.(*store.ListOutput)
+	assert.Equal(t, len(dataPage.Rows), 0)
+
+	//list search with name and status
+	listInput = &ListInput{}
+	reqBody = `{"page_size": 1, "page": 1, "name": "a", "status": "1"}`
+	err = json.Unmarshal([]byte(reqBody), listInput)
+	assert.Nil(t, err)
+	ctx.SetInput(listInput)
+	retPage, err = handler.List(ctx)
+	assert.Nil(t, err)
+	dataPage = retPage.(*store.ListOutput)
+	assert.Equal(t, len(dataPage.Rows), 1)
+
 	//list search with name and label
 	listInput = &ListInput{}
 	reqBody = `{"page_size": 1, "page": 1, "name": "a", "label":"l1:v1"}`
@@ -958,6 +996,17 @@ func TestRoute(t *testing.T) {
 	dataPage = retPage.(*store.ListOutput)
 	assert.Equal(t, len(dataPage.Rows), 1)
 
+	//list search with uri,name, status and label
+	listInput = &ListInput{}
+	reqBody = `{"page_size": 1, "page": 1, "name": "a", "status": "1", "uri": "index", "label":"l1:v1"}`
+	err = json.Unmarshal([]byte(reqBody), listInput)
+	assert.Nil(t, err)
+	ctx.SetInput(listInput)
+	retPage, err = handler.List(ctx)
+	assert.Nil(t, err)
+	dataPage = retPage.(*store.ListOutput)
+	assert.Equal(t, len(dataPage.Rows), 1)
+
 	//create route using uris
 	route3 := &entity.Route{}
 	reqBody = `{