This is an automated email from the ASF dual-hosted git repository.
membphis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 038c078 test: add route with vars (E2E) (#895)
038c078 is described below
commit 038c078eb5fb9b39642ff47d0456538a652ae614
Author: idbeta <[email protected]>
AuthorDate: Mon Nov 30 12:03:27 2020 +0800
test: add route with vars (E2E) (#895)
close #633
---
api/test/e2e/base.go | 15 +-
api/test/e2e/route_with_vars_test.go | 317 +++++++++++++++++++++++++++++++++++
2 files changed, 327 insertions(+), 5 deletions(-)
diff --git a/api/test/e2e/base.go b/api/test/e2e/base.go
index 4d33b80..4633fd8 100644
--- a/api/test/e2e/base.go
+++ b/api/test/e2e/base.go
@@ -125,6 +125,7 @@ type HttpTestCase struct {
Query string
Body string
Headers map[string]string
+ Headers_test map[string]interface{}
ExpectStatus int
ExpectCode int
ExpectMessage string
@@ -139,15 +140,15 @@ func testCaseCheck(tc HttpTestCase) {
var req *httpexpect.Request
switch tc.Method {
case http.MethodGet:
- req = expectObj.GET(tc.Path, tc.Query)
+ req = expectObj.GET(tc.Path)
case http.MethodPut:
- req = expectObj.PUT(tc.Path, tc.Query)
+ req = expectObj.PUT(tc.Path)
case http.MethodPost:
- req = expectObj.POST(tc.Path, tc.Query)
+ req = expectObj.POST(tc.Path)
case http.MethodDelete:
- req = expectObj.DELETE(tc.Path, tc.Query)
+ req = expectObj.DELETE(tc.Path)
case http.MethodPatch:
- req = expectObj.PATCH(tc.Path, tc.Query)
+ req = expectObj.PATCH(tc.Path)
default:
}
@@ -159,6 +160,10 @@ func testCaseCheck(tc HttpTestCase) {
time.Sleep(tc.Sleep)
}
+ if tc.Query != "" {
+ req.WithQueryString(tc.Query)
+ }
+
//set header
for key, val := range tc.Headers {
req.WithHeader(key, val)
diff --git a/api/test/e2e/route_with_vars_test.go
b/api/test/e2e/route_with_vars_test.go
new file mode 100644
index 0000000..3840fe9
--- /dev/null
+++ b/api/test/e2e/route_with_vars_test.go
@@ -0,0 +1,317 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package e2e
+
+import (
+ "net/http"
+ "testing"
+)
+
+func TestRoute_with_vars(t *testing.T) {
+ tests := []HttpTestCase{
+ {
+ caseDesc: "add route with vars (args)",
+ Object: MangerApiExpect(t),
+ Method: http.MethodPut,
+ Path: "/apisix/admin/routes/r1",
+ Body: `{
+ "uri": "/hello",
+ "vars": [
+ ["arg_name","==","aaa"]
+ ],
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": [{
+ "host": "172.16.238.20",
+ "port": 1980,
+ "weight": 1
+ }]
+ }
+ }`,
+ Headers: map[string]string{"Authorization": token},
+ ExpectStatus: http.StatusOK,
+ },
+
+ {
+ caseDesc: "hit the route with right args",
+ Object: APISIXExpect(t),
+ Method: http.MethodGet,
+ Path: `/hello`,
+ Query: "name=aaa",
+ ExpectStatus: http.StatusOK,
+ Sleep: sleepTime,
+ },
+
+ {
+ caseDesc: "hit the route with wrong args",
+ Object: APISIXExpect(t),
+ Method: http.MethodGet,
+ Path: `/hello`,
+ Query: "name=bbb",
+ ExpectStatus: http.StatusNotFound,
+ Sleep: sleepTime,
+ },
+
+ {
+ caseDesc: "hit the route with no args",
+ Object: APISIXExpect(t),
+ Method: http.MethodGet,
+ Path: `/hello`,
+ ExpectStatus: http.StatusNotFound,
+ Sleep: sleepTime,
+ },
+
+ {
+ caseDesc: "update route with vars (header)",
+ Object: MangerApiExpect(t),
+ Method: http.MethodPut,
+ Path: "/apisix/admin/routes/r1",
+ Body: `{
+ "uri": "/hello",
+ "vars": [
+ ["http_k","==","header"]
+ ],
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": [{
+ "host": "172.16.238.20",
+ "port": 1980,
+ "weight": 1
+ }]
+ }
+ }`,
+ Headers: map[string]string{"Authorization": token},
+ ExpectStatus: http.StatusOK,
+ },
+
+ {
+ caseDesc: "hit the route with right header",
+ Object: APISIXExpect(t),
+ Method: http.MethodGet,
+ Headers: map[string]string{"k": "header"},
+ Path: `/hello`,
+ ExpectStatus: http.StatusOK,
+ Sleep: sleepTime,
+ },
+
+ {
+ caseDesc: "hit the route with wrong header",
+ Object: APISIXExpect(t),
+ Method: http.MethodGet,
+ Headers: map[string]string{"k": "jack"},
+ Path: `/hello`,
+ ExpectStatus: http.StatusNotFound,
+ Sleep: sleepTime,
+ },
+
+ {
+ caseDesc: "hit the route with no header",
+ Object: APISIXExpect(t),
+ Method: http.MethodGet,
+ Path: `/hello`,
+ ExpectStatus: http.StatusNotFound,
+ Sleep: sleepTime,
+ },
+
+ {
+ caseDesc: "update route with vars (cookie)",
+ Object: MangerApiExpect(t),
+ Method: http.MethodPut,
+ Path: "/apisix/admin/routes/r1",
+ Body: `{
+ "uri": "/hello",
+ "vars": [
+
["http_cookie","==","_octo=GH1.1.572248189.1598928545;
_device_id=2c1a1a52074e66a3a008e4b73c690500; logged_in=yes;"]
+ ],
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": [{
+ "host": "172.16.238.20",
+ "port": 1980,
+ "weight": 1
+ }]
+ }
+ }`,
+ Headers: map[string]string{"Authorization": token},
+ ExpectStatus: http.StatusOK,
+ },
+
+ {
+ caseDesc: "hit the route with right Cookie",
+ Object: APISIXExpect(t),
+ Method: http.MethodGet,
+ Headers: map[string]string{"Cookie":
"_octo=GH1.1.572248189.1598928545; _device_id=2c1a1a52074e66a3a008e4b73c690500;
logged_in=yes;"},
+ Path: `/hello`,
+ ExpectStatus: http.StatusOK,
+ Sleep: sleepTime,
+ },
+
+ {
+ caseDesc: "hit the route with wrong Cookie",
+ Object: APISIXExpect(t),
+ Method: http.MethodGet,
+ Headers: map[string]string{"Cookie": "jack"},
+ Path: `/hello`,
+ ExpectStatus: http.StatusNotFound,
+ Sleep: sleepTime,
+ },
+
+ {
+ caseDesc: "hit the route with no Cookie",
+ Object: APISIXExpect(t),
+ Method: http.MethodGet,
+ Path: `/hello`,
+ ExpectStatus: http.StatusNotFound,
+ Sleep: sleepTime,
+ },
+
+ {
+ caseDesc: "delete route",
+ Object: MangerApiExpect(t),
+ Method: http.MethodDelete,
+ Path: "/apisix/admin/routes/r1",
+ Headers: map[string]string{"Authorization": token},
+ ExpectStatus: http.StatusOK,
+ Sleep: sleepTime,
+ },
+
+ {
+ caseDesc: "add route with multiple vars (args, cookie
and header)",
+ Object: MangerApiExpect(t),
+ Method: http.MethodPut,
+ Path: "/apisix/admin/routes/r1",
+ Body: `{
+ "uri": "/hello",
+ "vars": [
+
["http_cookie","==","_octo=GH1.1.572248189.1598928545;
_device_id=2c1a1a52074e66a3a008e4b73c690500; logged_in=yes;"],
+ ["http_k","==","header"],
+ ["arg_name","==","aaa"]
+ ],
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": [{
+ "host": "172.16.238.20",
+ "port": 1980,
+ "weight": 1
+ }]
+ }
+ }`,
+ Headers: map[string]string{"Authorization": token},
+ ExpectStatus: http.StatusOK,
+ },
+
+ {
+ caseDesc: "hit the route with right parameters",
+ Object: APISIXExpect(t),
+ Method: http.MethodGet,
+ Headers: map[string]string{"k": "header",
"Cookie": "_octo=GH1.1.572248189.1598928545;
_device_id=2c1a1a52074e66a3a008e4b73c690500; logged_in=yes;"},
+ Path: `/hello`,
+ Query: "name=aaa",
+ ExpectStatus: http.StatusOK,
+ Sleep: sleepTime,
+ },
+
+ {
+ caseDesc: "hit the route with wrong arg",
+ Object: APISIXExpect(t),
+ Method: http.MethodGet,
+ Headers: map[string]string{"k": "header",
"Cookie": "_octo=GH1.1.572248189.1598928545;
_device_id=2c1a1a52074e66a3a008e4b73c690500; logged_in=yes;"},
+ Path: `/hello`,
+ ExpectStatus: http.StatusNotFound,
+ Sleep: sleepTime,
+ },
+
+ {
+ caseDesc: "hit the route with wrong header",
+ Object: APISIXExpect(t),
+ Method: http.MethodGet,
+ Headers: map[string]string{"k": "test", "Cookie":
"_octo=GH1.1.572248189.1598928545; _device_id=2c1a1a52074e66a3a008e4b73c690500;
logged_in=yes;"},
+ Path: `/hello`,
+ Query: "name=aaa",
+ ExpectStatus: http.StatusNotFound,
+ Sleep: sleepTime,
+ },
+
+ {
+ caseDesc: "hit the route with wrong cookie",
+ Object: APISIXExpect(t),
+ Method: http.MethodGet,
+ Headers: map[string]string{"k": "header",
"Cookie": "_octo=GH1.1.572248189.1598928545; logged_in=yes;"},
+ Path: `/hello`,
+ Query: "name=aaa",
+ ExpectStatus: http.StatusNotFound,
+ Sleep: sleepTime,
+ },
+
+ {
+ caseDesc: "delete route",
+ Object: MangerApiExpect(t),
+ Method: http.MethodDelete,
+ Path: "/apisix/admin/routes/r1",
+ Headers: map[string]string{"Authorization": token},
+ ExpectStatus: http.StatusOK,
+ Sleep: sleepTime,
+ },
+
+ {
+ caseDesc: "add route with vars (args is digital)",
+ Object: MangerApiExpect(t),
+ Method: http.MethodPut,
+ Path: "/apisix/admin/routes/r1",
+ Body: `{
+ "uri": "/hello",
+ "vars": [
+ ["arg_name","==",111]
+ ],
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": [{
+ "host": "172.16.238.20",
+ "port": 1980,
+ "weight": 1
+ }]
+ }
+ }`,
+ Headers: map[string]string{"Authorization": token},
+ ExpectStatus: http.StatusOK,
+ },
+
+ {
+ caseDesc: "verify route",
+ Object: APISIXExpect(t),
+ Method: http.MethodGet,
+ Path: `/hello`,
+ Query: "name=111",
+ ExpectStatus: http.StatusOK,
+ Sleep: sleepTime,
+ },
+
+ {
+ caseDesc: "delete the route with vars (args is
digital)",
+ Object: MangerApiExpect(t),
+ Method: http.MethodDelete,
+ Path: "/apisix/admin/routes/r1",
+ Headers: map[string]string{"Authorization": token},
+ ExpectStatus: http.StatusOK,
+ Sleep: sleepTime,
+ },
+ }
+
+ for _, tc := range tests {
+ testCaseCheck(tc)
+ }
+}