Skip to content

Commit d39951b

Browse files
imjoeyJayceanjuzhiyuan
authored
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 <[email protected]> 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: 琚致远 <[email protected]> feat: add tips when plugin type is auth and schemaType is not consumer (#1219) Co-authored-by: 琚致远 <[email protected]> * Fix indent format problem Co-authored-by: 琚致远 <[email protected]> Co-authored-by: JinChen <[email protected]> Co-authored-by: 琚致远 <[email protected]>
1 parent d194c15 commit d39951b

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

api/internal/handler/route/route.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"os"
2424
"path/filepath"
2525
"reflect"
26+
"strconv"
2627
"strings"
2728

2829
"github.com/gin-gonic/gin"
@@ -178,9 +179,10 @@ func (h *Handler) Get(c droplet.Context) (interface{}, error) {
178179
}
179180

180181
type ListInput struct {
181-
Name string `auto_read:"name,query"`
182-
URI string `auto_read:"uri,query"`
183-
Label string `auto_read:"label,query"`
182+
Name string `auto_read:"name,query"`
183+
URI string `auto_read:"uri,query"`
184+
Label string `auto_read:"label,query"`
185+
Status string `auto_read:"status,query"`
184186
store.Pagination
185187
}
186188

@@ -219,6 +221,10 @@ func (h *Handler) List(c droplet.Context) (interface{}, error) {
219221
return false
220222
}
221223

224+
if input.Status != "" && strconv.Itoa(int(obj.(*entity.Route).Status)) != input.Status {
225+
return false
226+
}
227+
222228
return true
223229
},
224230
Format: func(obj interface{}) interface{} {

api/internal/handler/route/route_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func TestRoute(t *testing.T) {
5959
"vars": [],
6060
"remote_addrs": ["127.0.0.0/8"],
6161
"methods": ["PUT", "GET"],
62+
"status": 1,
6263
"upstream": {
6364
"type": "roundrobin",
6465
"nodes": [{
@@ -415,6 +416,7 @@ func TestRoute(t *testing.T) {
415416
"hosts": ["foo.com", "*.bar.com"],
416417
"remote_addrs": ["127.0.0.0/8"],
417418
"methods": ["PUT", "GET"],
419+
"status": 1,
418420
"labels": {
419421
"l1": "v1",
420422
"l2": "v2"
@@ -925,6 +927,42 @@ func TestRoute(t *testing.T) {
925927
dataPage = retPage.(*store.ListOutput)
926928
assert.Equal(t, len(dataPage.Rows), 0)
927929

930+
// list search and status match
931+
listInput = &ListInput{}
932+
reqBody = `{"page_size": 1, "page": 1, "status": "1"}`
933+
err = json.Unmarshal([]byte(reqBody), listInput)
934+
assert.Nil(t, err)
935+
ctx.SetInput(listInput)
936+
retPage, err = handler.List(ctx)
937+
assert.Nil(t, err)
938+
dataPage = retPage.(*store.ListOutput)
939+
assert.Equal(t, len(dataPage.Rows), 1)
940+
941+
//sleep
942+
time.Sleep(time.Duration(100) * time.Millisecond)
943+
944+
// list search and status not match
945+
listInput = &ListInput{}
946+
reqBody = `{"page_size": 1, "page": 1, "name": "a", "status": "0"}`
947+
err = json.Unmarshal([]byte(reqBody), listInput)
948+
assert.Nil(t, err)
949+
ctx.SetInput(listInput)
950+
retPage, err = handler.List(ctx)
951+
assert.Nil(t, err)
952+
dataPage = retPage.(*store.ListOutput)
953+
assert.Equal(t, len(dataPage.Rows), 0)
954+
955+
//list search with name and status
956+
listInput = &ListInput{}
957+
reqBody = `{"page_size": 1, "page": 1, "name": "a", "status": "1"}`
958+
err = json.Unmarshal([]byte(reqBody), listInput)
959+
assert.Nil(t, err)
960+
ctx.SetInput(listInput)
961+
retPage, err = handler.List(ctx)
962+
assert.Nil(t, err)
963+
dataPage = retPage.(*store.ListOutput)
964+
assert.Equal(t, len(dataPage.Rows), 1)
965+
928966
//list search with name and label
929967
listInput = &ListInput{}
930968
reqBody = `{"page_size": 1, "page": 1, "name": "a", "label":"l1:v1"}`
@@ -958,6 +996,17 @@ func TestRoute(t *testing.T) {
958996
dataPage = retPage.(*store.ListOutput)
959997
assert.Equal(t, len(dataPage.Rows), 1)
960998

999+
//list search with uri,name, status and label
1000+
listInput = &ListInput{}
1001+
reqBody = `{"page_size": 1, "page": 1, "name": "a", "status": "1", "uri": "index", "label":"l1:v1"}`
1002+
err = json.Unmarshal([]byte(reqBody), listInput)
1003+
assert.Nil(t, err)
1004+
ctx.SetInput(listInput)
1005+
retPage, err = handler.List(ctx)
1006+
assert.Nil(t, err)
1007+
dataPage = retPage.(*store.ListOutput)
1008+
assert.Equal(t, len(dataPage.Rows), 1)
1009+
9611010
//create route using uris
9621011
route3 := &entity.Route{}
9631012
reqBody = `{

0 commit comments

Comments
 (0)