Jaycean commented on a change in pull request #1606: URL: https://github.com/apache/apisix-dashboard/pull/1606#discussion_r596059021
########## File path: api/test/e2enew/route/route_test.go ########## @@ -0,0 +1,151 @@ +/* + * 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 route + +import ( + "net/http" + + "github.com/onsi/ginkgo" + "github.com/onsi/ginkgo/extensions/table" + + "github.com/apisix/manager-api/test/e2enew/base" +) + +var _ = ginkgo.Describe("Route", func() { + table.DescribeTable("test route create and update", + func(tc base.HttpTestCase) { + base.RunTestCase(tc) + }, + table.Entry("create route1 success", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r1", + Body: `{ + "name": "route1", + "uri": "/hello_", + "upstream": { + "nodes": { + "` + base.UpstreamIp + `:1980": 1 + }, + "type": "roundrobin" + } + }`, + Headers: map[string]string{"Authorization": base.GetToken()}, + ExpectStatus: http.StatusOK, + }), + table.Entry("create route2 success", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r2", + Body: `{ + "name": "route2", + "uri": "/hello_", + "upstream": { + "nodes": { + "` + base.UpstreamIp + `:1980": 1 + }, + "type": "roundrobin" + } + }`, + Headers: map[string]string{"Authorization": base.GetToken()}, + ExpectStatus: http.StatusOK, + }), + table.Entry("create route failed, name existed", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodPost, + Path: "/apisix/admin/routes", + Body: `{ + "name": "route2", + "uri": "/hello_", + "upstream": { + "nodes": { + "` + base.UpstreamIp + `:1980": 1 + }, + "type": "roundrobin" + } + }`, + Headers: map[string]string{"Authorization": base.GetToken()}, + ExpectStatus: http.StatusBadRequest, + ExpectBody: `route name exists`, + Sleep: base.SleepTime, + }), + table.Entry("update route2 failed, name existed", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r2", + Body: `{ + "name": "route1", + "uri": "/hello_", + "upstream": { + "nodes": { + "` + base.UpstreamIp + `:1980": 1 + }, + "type": "roundrobin" + } + }`, + Headers: map[string]string{"Authorization": base.GetToken()}, + ExpectStatus: http.StatusBadRequest, + ExpectBody: `route name exists`, + }), + table.Entry("update route2 success, name not change", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r2", + Body: `{ + "name": "route2", + "uri": "/hello", + "upstream": { + "nodes": { + "` + base.UpstreamIp + `:1980": 1 + }, + "type": "roundrobin" + } + }`, + Headers: map[string]string{"Authorization": base.GetToken()}, + ExpectStatus: http.StatusOK, + }), + table.Entry("hit route1", base.HttpTestCase{ + Object: base.APISIXExpect(), + Method: http.MethodGet, + Path: "/hello_", + ExpectStatus: http.StatusOK, + ExpectBody: "hello world", + Sleep: base.SleepTime, + }), + table.Entry("hit route2", base.HttpTestCase{ + Object: base.APISIXExpect(), + Method: http.MethodGet, + Path: "/hello_", Review comment: The path of route2 is updated to "/hello". This test case cannot be tested "hit route2". ########## File path: api/test/e2enew/route/route_test.go ########## @@ -0,0 +1,151 @@ +/* + * 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 route + +import ( + "net/http" + + "github.com/onsi/ginkgo" + "github.com/onsi/ginkgo/extensions/table" + + "github.com/apisix/manager-api/test/e2enew/base" +) + +var _ = ginkgo.Describe("Route", func() { + table.DescribeTable("test route create and update", + func(tc base.HttpTestCase) { + base.RunTestCase(tc) + }, + table.Entry("create route1 success", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r1", + Body: `{ + "name": "route1", + "uri": "/hello_", + "upstream": { + "nodes": { + "` + base.UpstreamIp + `:1980": 1 + }, + "type": "roundrobin" + } + }`, + Headers: map[string]string{"Authorization": base.GetToken()}, + ExpectStatus: http.StatusOK, + }), + table.Entry("create route2 success", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r2", + Body: `{ + "name": "route2", + "uri": "/hello_", + "upstream": { + "nodes": { + "` + base.UpstreamIp + `:1980": 1 + }, + "type": "roundrobin" + } + }`, + Headers: map[string]string{"Authorization": base.GetToken()}, + ExpectStatus: http.StatusOK, + }), + table.Entry("create route failed, name existed", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodPost, + Path: "/apisix/admin/routes", + Body: `{ + "name": "route2", + "uri": "/hello_", + "upstream": { + "nodes": { + "` + base.UpstreamIp + `:1980": 1 + }, + "type": "roundrobin" + } + }`, + Headers: map[string]string{"Authorization": base.GetToken()}, + ExpectStatus: http.StatusBadRequest, + ExpectBody: `route name exists`, + Sleep: base.SleepTime, + }), + table.Entry("update route2 failed, name existed", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r2", + Body: `{ + "name": "route1", + "uri": "/hello_", + "upstream": { + "nodes": { + "` + base.UpstreamIp + `:1980": 1 + }, + "type": "roundrobin" + } + }`, + Headers: map[string]string{"Authorization": base.GetToken()}, + ExpectStatus: http.StatusBadRequest, + ExpectBody: `route name exists`, + }), + table.Entry("update route2 success, name not change", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r2", + Body: `{ + "name": "route2", + "uri": "/hello", + "upstream": { + "nodes": { + "` + base.UpstreamIp + `:1980": 1 + }, + "type": "roundrobin" + } + }`, + Headers: map[string]string{"Authorization": base.GetToken()}, + ExpectStatus: http.StatusOK, + }), + table.Entry("hit route1", base.HttpTestCase{ + Object: base.APISIXExpect(), + Method: http.MethodGet, + Path: "/hello_", + ExpectStatus: http.StatusOK, + ExpectBody: "hello world", + Sleep: base.SleepTime, + }), + table.Entry("hit route2", base.HttpTestCase{ + Object: base.APISIXExpect(), + Method: http.MethodGet, + Path: "/hello_", + ExpectStatus: http.StatusOK, + ExpectBody: "hello world", + }), + table.Entry("delete route1", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodDelete, + Path: "/apisix/admin/routes/r1", + Headers: map[string]string{"Authorization": base.GetToken()}, + ExpectStatus: http.StatusOK, + }), + table.Entry("delete route2", base.HttpTestCase{ + Object: base.ManagerApiExpect(), + Method: http.MethodDelete, + Path: "/apisix/admin/routes/r2", + Headers: map[string]string{"Authorization": base.GetToken()}, + ExpectStatus: http.StatusOK, + }), Review comment: IMHO, we should add test cases that verify the data is deleted after deleting route data. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
