You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by kv...@apache.org on 2020/11/27 08:01:54 UTC

[apisix-dashboard] branch master updated: test: add route with methods (#890)

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

kvn 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 b2f3901  test: add route with methods (#890)
b2f3901 is described below

commit b2f3901945304fd1b67c8578bf33113016289f7d
Author: idbeta <id...@gmail.com>
AuthorDate: Fri Nov 27 16:01:48 2020 +0800

    test: add route with methods (#890)
    
    * test: add route with methos
    
    * fix: update the function name
    
    * test: update testcase add verify put, delete, patch
---
 api/test/e2e/route_with_methods_test.go | 297 ++++++++++++++++++++++++++++++++
 1 file changed, 297 insertions(+)

diff --git a/api/test/e2e/route_with_methods_test.go b/api/test/e2e/route_with_methods_test.go
new file mode 100644
index 0000000..b5590ed
--- /dev/null
+++ b/api/test/e2e/route_with_methods_test.go
@@ -0,0 +1,297 @@
+/*
+ * 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_methods(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "add route with invalid method",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+					 "uri": "/hello",
+					 "methods": ["TEST"],
+					 "upstream": {
+						 "type": "roundrobin",
+						 "nodes": [{
+							 "host": "172.16.238.20",
+							 "port": 1980,
+							 "weight": 1
+						 }]
+					 }
+				 }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusBadRequest,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusNotFound,
+			Sleep:        sleepTime,
+		},
+		{
+			caseDesc: "add route with valid method",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+					 "uri": "/hello",
+					 "methods": ["GET"],
+					 "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",
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "hello world",
+			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,
+		},
+		{
+			caseDesc: "add route with valid methods",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+					 "uri": "/hello",
+					 "methods": ["GET", "POST", "PUT", "DELETE", "PATCH"],
+					 "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 by post",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodPost,
+			Path:         "/hello",
+			Body:         `test=test`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "hello world",
+			Sleep:        sleepTime,
+		},
+		{
+			caseDesc:     "verify route by put",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodPut,
+			Path:         "/hello",
+			Body:         `test=test`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "hello world",
+			Sleep:        sleepTime,
+		},
+		{
+			caseDesc:     "verify route by get",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "hello world",
+			Sleep:        sleepTime,
+		},
+		{
+			caseDesc:     "verify route by delete",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodDelete,
+			Path:         "/hello",
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "hello world",
+			Sleep:        sleepTime,
+		},
+		{
+			caseDesc:     "verify route by patch",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodPatch,
+			Path:         "/hello",
+			Body:         `test=test`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "hello world",
+			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,
+		},
+		{
+			caseDesc: "add route with lower case methods",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+					 "uri": "/hello",
+					 "methods": ["GET", "post"],
+					 "upstream": {
+						 "type": "roundrobin",
+						 "nodes": [{
+							 "host": "172.16.238.20",
+							 "port": 1980,
+							 "weight": 1
+						 }]
+					 }
+				}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusBadRequest,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusNotFound,
+			Sleep:        sleepTime,
+		},
+		{
+			caseDesc: "add route with methods GET",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+					 "uri": "/hello",
+					 "methods": ["GET"],
+					 "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 by get",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "hello world",
+			Sleep:        sleepTime,
+		},
+		{
+			caseDesc:     "verify route by post",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodPost,
+			Path:         "/hello",
+			Body:         `test=test`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusNotFound,
+			Sleep:        sleepTime,
+		},
+		{
+			caseDesc: "update route methods to POST",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+					 "uri": "/hello",
+					 "methods": ["POST"],
+					 "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 by get",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusNotFound,
+			Sleep:        sleepTime,
+		},
+		{
+			caseDesc:     "verify route by post",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodPost,
+			Path:         "/hello",
+			Body:         `test=test`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "hello world",
+			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,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}