Skip to content

Commit

Permalink
Merge branch 'master' into export_route_from_openapi
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaycean authored Jan 8, 2021
2 parents 21dc483 + 40d8f97 commit 3093f3c
Show file tree
Hide file tree
Showing 34 changed files with 1,797 additions and 238 deletions.
11 changes: 11 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Please answer these questions before submitting a pull request
- [ ] Bugfix
- [ ] New feature provided
- [ ] Improve performance
- [ ] Backport patches

- Related issues

Expand All @@ -16,3 +17,13 @@ ___
___
### New feature or improvement
- Describe the details and related test reports.

___
### Backport patches
- Why need to backport?

- Source branch

- Related commits and pull requests

- Target branch
2 changes: 1 addition & 1 deletion api/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3
master
12 changes: 11 additions & 1 deletion api/build-tools/schema-sync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ local fake_module_list = {
'ngx.errlog',
'ngx.process',
'ngx.re',
'ngx.ssl',
'net.url',
'opentracing.tracer',
'pb',
Expand All @@ -35,6 +36,7 @@ local fake_module_list = {

'resty.cookie',
'resty.core.regex',
'resty.core.base',
'resty.hmac',
'resty.http',
'resty.ipmatcher',
Expand All @@ -52,6 +54,9 @@ local fake_module_list = {
'resty.rediscluster',
'resty.signal',
'resty.string',
'resty.aes',
'resty.radixtree',
'resty.expr.v1',

'apisix.consumer',
'apisix.core.json',
Expand Down Expand Up @@ -84,6 +89,8 @@ ngx.socket = {}
ngx.thread = {}
ngx.worker = {}
ngx.re.gmatch = empty_function
ngx.req = {}
ngx.config = {}
ngx.shared = {
["plugin-api-breaker"] = {}
}
Expand Down Expand Up @@ -112,7 +119,10 @@ package.loaded["apisix.core"] = {
table = {
insert = empty_function
},
string = {}
string = {},
version = {
VERSION = ""
}
}


Expand Down
12 changes: 9 additions & 3 deletions api/internal/handler/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"path/filepath"
"reflect"
"strconv"
"strings"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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{} {
Expand Down
49 changes: 49 additions & 0 deletions api/internal/handler/route/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": [{
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"}`
Expand Down Expand Up @@ -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 = `{
Expand Down
6 changes: 3 additions & 3 deletions api/internal/handler/route_online_debug/route_online_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (h *Handler) ApplyRoute(r *gin.Engine) {
type ParamsInput struct {
URL string `json:"url,omitempty"`
RequestProtocol string `json:"request_protocol,omitempty"`
BodyParams map[string]string `json:"body_params,omitempty"`
BodyParams string `json:"body_params,omitempty"`
Method string `json:"method,omitempty"`
HeaderParams map[string][]string `json:"header_params,omitempty"`
}
Expand Down Expand Up @@ -88,11 +88,11 @@ type HTTPProtocolSupport struct {

func (h *HTTPProtocolSupport) RequestForwarding(c droplet.Context) (interface{}, error) {
paramsInput := c.Input().(*ParamsInput)
bodyParams, _ := json.Marshal(paramsInput.BodyParams)
bodyParams := paramsInput.BodyParams
client := &http.Client{}

client.Timeout = 5 * time.Second
req, err := http.NewRequest(strings.ToUpper(paramsInput.Method), paramsInput.URL, strings.NewReader(string(bodyParams)))
req, err := http.NewRequest(strings.ToUpper(paramsInput.Method), paramsInput.URL, strings.NewReader(bodyParams))
if err != nil {
return &data.SpecCodeResponse{StatusCode: http.StatusInternalServerError}, err
}
Expand Down
5 changes: 1 addition & 4 deletions api/test/e2e/route_online_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,7 @@ func TestRoute_Online_Debug_Route_With_Body_Params(t *testing.T) {
"url": "` + APISIXInternalUrl + `/hello",
"request_protocol": "http",
"method": "POST",
"body_params": {
"name": "test",
"desc": "online debug route with body params"
}
"body_params": "{\"name\":\"test\",\"desc\":\"online debug route with body params\"}"
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
Expand Down
Loading

0 comments on commit 3093f3c

Please sign in to comment.