From 12d7041f06c2449338288de98690003cef534985 Mon Sep 17 00:00:00 2001 From: EnableAsync Date: Mon, 16 Nov 2020 13:04:48 +0800 Subject: [PATCH 1/9] test: add e2e test for config route with service_id or upstream_id --- api/test/e2e/route_service_upstream_test.go | 161 ++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 api/test/e2e/route_service_upstream_test.go diff --git a/api/test/e2e/route_service_upstream_test.go b/api/test/e2e/route_service_upstream_test.go new file mode 100644 index 0000000000..a60a6098eb --- /dev/null +++ b/api/test/e2e/route_service_upstream_test.go @@ -0,0 +1,161 @@ +/* + * 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_Invalid_Service_And_Service(t *testing.T) { + tests := []HttpTestCase{ + { + caseDesc: "use service that not exist", + Object: MangerApiExpect(t), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r1", + Body: `{ + "uri": "/hello_", + "service_id": "not-exists" + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusBadRequest, + }, + { + caseDesc: "use upstream that not exist", + Object: MangerApiExpect(t), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r1", + Body: `{ + "uri": "/hello_", + "upstream_id": "not-exists" + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusBadRequest, + }, + { + caseDesc: "create service and upstream together at the same time", + Object: MangerApiExpect(t), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r1", + Body: `{ + "uri": "/hello_", + "service_id": "not-exists-service", + "upstream_id": "not-exists-upstream", + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusBadRequest, + }, + } + for _, tc := range tests { + testCaseCheck(tc) + } +} + +func TestRoute_Upstream(t *testing.T) { + tests := []HttpTestCase{ + { + caseDesc: "create upstream", + Object: MangerApiExpect(t), + Method: http.MethodPut, + Path: "/apisix/admin/upstreams/1", + Body: `{ + "nodes": [{ + "host": "172.16.238.20", + "port": 1980, + "weight": 1 + }], + "type": "roundrobin" + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "create route using the upstream just created", + Object: MangerApiExpect(t), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r1", + Body: `{ + "uri": "/server_port", + "upstream_id": "1" + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + Sleep: sleepTime, + }, + { + caseDesc: "hit the route just created", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/server_port", + ExpectStatus: http.StatusOK, + ExpectBody: "1980", + Sleep: sleepTime, + }, + } + for _, tc := range tests { + testCaseCheck(tc) + } +} + +func TestRoute_Service(t *testing.T) { + tests := []HttpTestCase{ + { + caseDesc: "create service", + Object: MangerApiExpect(t), + Method: http.MethodPut, + Path: "/apisix/admin/services/200", + Body: `{ + "upstream": { + "type": "roundrobin", + "nodes": [{ + "host": "172.16.238.20", + "port": 1980, + "weight": 1 + }] + } + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "create route using the service just created", + Object: MangerApiExpect(t), + Method: http.MethodPut, + Path: "/apisix/admin/routes/r2", + Body: `{ + "uri": "/server_port_service", + "service_id": "200" + }`, + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + Sleep: sleepTime, + }, + { + caseDesc: "hit the route just created", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/server_port_service", + ExpectStatus: http.StatusOK, + ExpectBody: "1980", + Sleep: sleepTime, + }, + } + for _, tc := range tests { + testCaseCheck(tc) + } +} From 210faae0b4d54cf7d779884e0a107591118ccf69 Mon Sep 17 00:00:00 2001 From: EnableAsync Date: Mon, 16 Nov 2020 15:00:35 +0800 Subject: [PATCH 2/9] test: fix route test --- api/test/e2e/route_service_upstream_test.go | 40 ++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/api/test/e2e/route_service_upstream_test.go b/api/test/e2e/route_service_upstream_test.go index a60a6098eb..d32b56d535 100644 --- a/api/test/e2e/route_service_upstream_test.go +++ b/api/test/e2e/route_service_upstream_test.go @@ -66,7 +66,7 @@ func TestRoute_Invalid_Service_And_Service(t *testing.T) { } } -func TestRoute_Upstream(t *testing.T) { +func TestRoute_Create_Upstream(t *testing.T) { tests := []HttpTestCase{ { caseDesc: "create upstream", @@ -112,7 +112,7 @@ func TestRoute_Upstream(t *testing.T) { } } -func TestRoute_Service(t *testing.T) { +func TestRoute_Create_Service(t *testing.T) { tests := []HttpTestCase{ { caseDesc: "create service", @@ -138,7 +138,7 @@ func TestRoute_Service(t *testing.T) { Method: http.MethodPut, Path: "/apisix/admin/routes/r2", Body: `{ - "uri": "/server_port_service", + "uri": "/server_port", "service_id": "200" }`, Headers: map[string]string{"Authorization": token}, @@ -149,7 +149,7 @@ func TestRoute_Service(t *testing.T) { caseDesc: "hit the route just created", Object: APISIXExpect(t), Method: http.MethodGet, - Path: "/server_port_service", + Path: "/server_port", ExpectStatus: http.StatusOK, ExpectBody: "1980", Sleep: sleepTime, @@ -159,3 +159,35 @@ func TestRoute_Service(t *testing.T) { testCaseCheck(tc) } } + +//func TestRoute_Delete_Upstream(t *testing.T) { +// tests := []HttpTestCase{ +// { +// caseDesc: "remove upstream before deleting route", +// Object: MangerApiExpect(t), +// Method: http.MethodDelete, +// Path: "/apisix/admin/upstreams/1", +// Headers: map[string]string{"Authorization": token}, +// ExpectStatus: http.StatusBadRequest, +// }, +// { +// caseDesc: "delete route", +// Object: MangerApiExpect(t), +// Method: http.MethodDelete, +// Path: "/apisix/admin/routes/r1", +// Headers: map[string]string{"Authorization": token}, +// ExpectStatus: http.StatusOK, +// }, +// { +// caseDesc: "remove upstream", +// Object: MangerApiExpect(t), +// Method: http.MethodDelete, +// Path: "/apisix/admin/upstreams/1", +// Headers: map[string]string{"Authorization": token}, +// ExpectStatus: http.StatusBadRequest, +// }, +// } +// for _, tc := range tests { +// testCaseCheck(tc) +// } +//} From ce62474dd3c7139f7345a1796428d4ab34d563e1 Mon Sep 17 00:00:00 2001 From: EnableAsync Date: Mon, 16 Nov 2020 15:07:21 +0800 Subject: [PATCH 3/9] test: fix route test --- api/test/e2e/route_service_upstream_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/test/e2e/route_service_upstream_test.go b/api/test/e2e/route_service_upstream_test.go index d32b56d535..d8325e1d55 100644 --- a/api/test/e2e/route_service_upstream_test.go +++ b/api/test/e2e/route_service_upstream_test.go @@ -138,7 +138,7 @@ func TestRoute_Create_Service(t *testing.T) { Method: http.MethodPut, Path: "/apisix/admin/routes/r2", Body: `{ - "uri": "/server_port", + "uri": "/hello", "service_id": "200" }`, Headers: map[string]string{"Authorization": token}, @@ -149,9 +149,9 @@ func TestRoute_Create_Service(t *testing.T) { caseDesc: "hit the route just created", Object: APISIXExpect(t), Method: http.MethodGet, - Path: "/server_port", + Path: "/hello", ExpectStatus: http.StatusOK, - ExpectBody: "1980", + ExpectBody: "hello world\n", Sleep: sleepTime, }, } From fa175297a614a935d9eac4857a7bb2b89a34697d Mon Sep 17 00:00:00 2001 From: EnableAsync Date: Mon, 16 Nov 2020 15:30:37 +0800 Subject: [PATCH 4/9] test: fix route test --- api/test/e2e/route_service_upstream_test.go | 80 ++++++++++++--------- 1 file changed, 48 insertions(+), 32 deletions(-) diff --git a/api/test/e2e/route_service_upstream_test.go b/api/test/e2e/route_service_upstream_test.go index d8325e1d55..416c8d65ac 100644 --- a/api/test/e2e/route_service_upstream_test.go +++ b/api/test/e2e/route_service_upstream_test.go @@ -55,7 +55,7 @@ func TestRoute_Invalid_Service_And_Service(t *testing.T) { Body: `{ "uri": "/hello_", "service_id": "not-exists-service", - "upstream_id": "not-exists-upstream", + "upstream_id": "not-exists-upstream" }`, Headers: map[string]string{"Authorization": token}, ExpectStatus: http.StatusBadRequest, @@ -160,34 +160,50 @@ func TestRoute_Create_Service(t *testing.T) { } } -//func TestRoute_Delete_Upstream(t *testing.T) { -// tests := []HttpTestCase{ -// { -// caseDesc: "remove upstream before deleting route", -// Object: MangerApiExpect(t), -// Method: http.MethodDelete, -// Path: "/apisix/admin/upstreams/1", -// Headers: map[string]string{"Authorization": token}, -// ExpectStatus: http.StatusBadRequest, -// }, -// { -// caseDesc: "delete route", -// Object: MangerApiExpect(t), -// Method: http.MethodDelete, -// Path: "/apisix/admin/routes/r1", -// Headers: map[string]string{"Authorization": token}, -// ExpectStatus: http.StatusOK, -// }, -// { -// caseDesc: "remove upstream", -// Object: MangerApiExpect(t), -// Method: http.MethodDelete, -// Path: "/apisix/admin/upstreams/1", -// Headers: map[string]string{"Authorization": token}, -// ExpectStatus: http.StatusBadRequest, -// }, -// } -// for _, tc := range tests { -// testCaseCheck(tc) -// } -//} +func TestRoute_Delete_Upstream(t *testing.T) { + tests := []HttpTestCase{ + { + caseDesc: "delete route", + Object: MangerApiExpect(t), + Method: http.MethodDelete, + Path: "/apisix/admin/routes/r1", + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "remove upstream", + Object: MangerApiExpect(t), + Method: http.MethodDelete, + Path: "/apisix/admin/upstreams/1", + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + } + for _, tc := range tests { + testCaseCheck(tc) + } +} + +func TestRoute_Delete_Service(t *testing.T) { + tests := []HttpTestCase{ + { + caseDesc: "delete route", + Object: MangerApiExpect(t), + Method: http.MethodDelete, + Path: "/apisix/admin/routes/r2", + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "remove service", + Object: MangerApiExpect(t), + Method: http.MethodDelete, + Path: "/apisix/admin/services/200", + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + } + for _, tc := range tests { + testCaseCheck(tc) + } +} From ed9babbe1c51e7ef5dda5f73d49bb5c30ca93312 Mon Sep 17 00:00:00 2001 From: EnableAsync Date: Mon, 16 Nov 2020 16:57:58 +0800 Subject: [PATCH 5/9] test: fix route test format --- api/test/e2e/route_service_upstream_test.go | 33 +++++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/api/test/e2e/route_service_upstream_test.go b/api/test/e2e/route_service_upstream_test.go index 416c8d65ac..6b91fc41af 100644 --- a/api/test/e2e/route_service_upstream_test.go +++ b/api/test/e2e/route_service_upstream_test.go @@ -28,7 +28,8 @@ func TestRoute_Invalid_Service_And_Service(t *testing.T) { Object: MangerApiExpect(t), Method: http.MethodPut, Path: "/apisix/admin/routes/r1", - Body: `{ + Body: ` + { "uri": "/hello_", "service_id": "not-exists" }`, @@ -40,7 +41,8 @@ func TestRoute_Invalid_Service_And_Service(t *testing.T) { Object: MangerApiExpect(t), Method: http.MethodPut, Path: "/apisix/admin/routes/r1", - Body: `{ + Body: ` + { "uri": "/hello_", "upstream_id": "not-exists" }`, @@ -52,7 +54,8 @@ func TestRoute_Invalid_Service_And_Service(t *testing.T) { Object: MangerApiExpect(t), Method: http.MethodPut, Path: "/apisix/admin/routes/r1", - Body: `{ + Body: ` + { "uri": "/hello_", "service_id": "not-exists-service", "upstream_id": "not-exists-upstream" @@ -73,7 +76,8 @@ func TestRoute_Create_Upstream(t *testing.T) { Object: MangerApiExpect(t), Method: http.MethodPut, Path: "/apisix/admin/upstreams/1", - Body: `{ + Body: ` + { "nodes": [{ "host": "172.16.238.20", "port": 1980, @@ -89,7 +93,8 @@ func TestRoute_Create_Upstream(t *testing.T) { Object: MangerApiExpect(t), Method: http.MethodPut, Path: "/apisix/admin/routes/r1", - Body: `{ + Body: ` + { "uri": "/server_port", "upstream_id": "1" }`, @@ -119,14 +124,15 @@ func TestRoute_Create_Service(t *testing.T) { Object: MangerApiExpect(t), Method: http.MethodPut, Path: "/apisix/admin/services/200", - Body: `{ + Body: ` + { "upstream": { - "type": "roundrobin", - "nodes": [{ - "host": "172.16.238.20", - "port": 1980, - "weight": 1 - }] + "type": "roundrobin", + "nodes": [{ + "host": "172.16.238.20", + "port": 1980, + "weight": 1 + }] } }`, Headers: map[string]string{"Authorization": token}, @@ -137,7 +143,8 @@ func TestRoute_Create_Service(t *testing.T) { Object: MangerApiExpect(t), Method: http.MethodPut, Path: "/apisix/admin/routes/r2", - Body: `{ + Body: ` + { "uri": "/hello", "service_id": "200" }`, From 01df9bef53834fec470bc387720303b2d60a8bfa Mon Sep 17 00:00:00 2001 From: EnableAsync Date: Mon, 16 Nov 2020 17:00:41 +0800 Subject: [PATCH 6/9] test: fix route test format --- api/test/e2e/route_service_upstream_test.go | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/api/test/e2e/route_service_upstream_test.go b/api/test/e2e/route_service_upstream_test.go index 6b91fc41af..5c86e1e281 100644 --- a/api/test/e2e/route_service_upstream_test.go +++ b/api/test/e2e/route_service_upstream_test.go @@ -28,8 +28,7 @@ func TestRoute_Invalid_Service_And_Service(t *testing.T) { Object: MangerApiExpect(t), Method: http.MethodPut, Path: "/apisix/admin/routes/r1", - Body: ` - { + Body: `{ "uri": "/hello_", "service_id": "not-exists" }`, @@ -41,8 +40,7 @@ func TestRoute_Invalid_Service_And_Service(t *testing.T) { Object: MangerApiExpect(t), Method: http.MethodPut, Path: "/apisix/admin/routes/r1", - Body: ` - { + Body: `{ "uri": "/hello_", "upstream_id": "not-exists" }`, @@ -54,8 +52,7 @@ func TestRoute_Invalid_Service_And_Service(t *testing.T) { Object: MangerApiExpect(t), Method: http.MethodPut, Path: "/apisix/admin/routes/r1", - Body: ` - { + Body: `{ "uri": "/hello_", "service_id": "not-exists-service", "upstream_id": "not-exists-upstream" @@ -76,8 +73,7 @@ func TestRoute_Create_Upstream(t *testing.T) { Object: MangerApiExpect(t), Method: http.MethodPut, Path: "/apisix/admin/upstreams/1", - Body: ` - { + Body: `{ "nodes": [{ "host": "172.16.238.20", "port": 1980, @@ -93,8 +89,7 @@ func TestRoute_Create_Upstream(t *testing.T) { Object: MangerApiExpect(t), Method: http.MethodPut, Path: "/apisix/admin/routes/r1", - Body: ` - { + Body: `{ "uri": "/server_port", "upstream_id": "1" }`, @@ -124,8 +119,7 @@ func TestRoute_Create_Service(t *testing.T) { Object: MangerApiExpect(t), Method: http.MethodPut, Path: "/apisix/admin/services/200", - Body: ` - { + Body: `{ "upstream": { "type": "roundrobin", "nodes": [{ @@ -143,8 +137,7 @@ func TestRoute_Create_Service(t *testing.T) { Object: MangerApiExpect(t), Method: http.MethodPut, Path: "/apisix/admin/routes/r2", - Body: ` - { + Body: `{ "uri": "/hello", "service_id": "200" }`, From feffc04b3959d80081d15bbaef3706bb1a27a57f Mon Sep 17 00:00:00 2001 From: EnableAsync <43645467+EnableAsync@users.noreply.github.com> Date: Mon, 16 Nov 2020 17:08:51 +0800 Subject: [PATCH 7/9] test: fix test format --- api/test/e2e/route_service_upstream_test.go | 26 ++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/api/test/e2e/route_service_upstream_test.go b/api/test/e2e/route_service_upstream_test.go index 5c86e1e281..2ea2446b03 100644 --- a/api/test/e2e/route_service_upstream_test.go +++ b/api/test/e2e/route_service_upstream_test.go @@ -74,12 +74,12 @@ func TestRoute_Create_Upstream(t *testing.T) { Method: http.MethodPut, Path: "/apisix/admin/upstreams/1", Body: `{ - "nodes": [{ - "host": "172.16.238.20", - "port": 1980, - "weight": 1 - }], - "type": "roundrobin" + "nodes": [{ + "host": "172.16.238.20", + "port": 1980, + "weight": 1 + }], + "type": "roundrobin" }`, Headers: map[string]string{"Authorization": token}, ExpectStatus: http.StatusOK, @@ -121,13 +121,13 @@ func TestRoute_Create_Service(t *testing.T) { Path: "/apisix/admin/services/200", Body: `{ "upstream": { - "type": "roundrobin", - "nodes": [{ - "host": "172.16.238.20", - "port": 1980, - "weight": 1 - }] - } + "type": "roundrobin", + "nodes": [{ + "host": "172.16.238.20", + "port": 1980, + "weight": 1 + }] + } }`, Headers: map[string]string{"Authorization": token}, ExpectStatus: http.StatusOK, From b776aa72cfb5201b2db419893dd8d23262aad859 Mon Sep 17 00:00:00 2001 From: EnableAsync Date: Tue, 17 Nov 2020 18:03:05 +0800 Subject: [PATCH 8/9] test: add test on data plane --- api/test/e2e/route_service_upstream_test.go | 193 +++++++++++++++----- 1 file changed, 144 insertions(+), 49 deletions(-) diff --git a/api/test/e2e/route_service_upstream_test.go b/api/test/e2e/route_service_upstream_test.go index 5c86e1e281..7b342f1b37 100644 --- a/api/test/e2e/route_service_upstream_test.go +++ b/api/test/e2e/route_service_upstream_test.go @@ -24,7 +24,7 @@ import ( func TestRoute_Invalid_Service_And_Service(t *testing.T) { tests := []HttpTestCase{ { - caseDesc: "use service that not exist", + caseDesc: "use service that not exist - dashboard", Object: MangerApiExpect(t), Method: http.MethodPut, Path: "/apisix/admin/routes/r1", @@ -35,6 +35,13 @@ func TestRoute_Invalid_Service_And_Service(t *testing.T) { Headers: map[string]string{"Authorization": token}, ExpectStatus: http.StatusBadRequest, }, + { + caseDesc: "hit invalid route on data plane", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello_", + ExpectCode: http.StatusNotFound, + }, { caseDesc: "use upstream that not exist", Object: MangerApiExpect(t), @@ -47,6 +54,13 @@ func TestRoute_Invalid_Service_And_Service(t *testing.T) { Headers: map[string]string{"Authorization": token}, ExpectStatus: http.StatusBadRequest, }, + { + caseDesc: "hit invalid route on data plane", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello_", + ExpectCode: http.StatusNotFound, + }, { caseDesc: "create service and upstream together at the same time", Object: MangerApiExpect(t), @@ -60,43 +74,82 @@ func TestRoute_Invalid_Service_And_Service(t *testing.T) { Headers: map[string]string{"Authorization": token}, ExpectStatus: http.StatusBadRequest, }, + { + caseDesc: "hit invalid route on data plane", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/hello_", + ExpectCode: http.StatusNotFound, + }, } for _, tc := range tests { testCaseCheck(tc) } } -func TestRoute_Create_Upstream(t *testing.T) { +func TestRoute_Create_Service(t *testing.T) { tests := []HttpTestCase{ { - caseDesc: "create upstream", + caseDesc: "create service", Object: MangerApiExpect(t), Method: http.MethodPut, - Path: "/apisix/admin/upstreams/1", + Path: "/apisix/admin/services/200", Body: `{ - "nodes": [{ - "host": "172.16.238.20", - "port": 1980, - "weight": 1 - }], - "type": "roundrobin" + "upstream": { + "type": "roundrobin", + "nodes": [ + { + "host": "172.16.238.20", + "port": 1980, + "weight": 1 + }, + { + "host": "172.16.238.20", + "port": 1981, + "weight": 1 + }, + { + "host": "172.16.238.20", + "port": 1982, + "weight": 1 + } + ] + } }`, Headers: map[string]string{"Authorization": token}, ExpectStatus: http.StatusOK, }, { - caseDesc: "create route using the upstream just created", + caseDesc: "create route using the service just created", Object: MangerApiExpect(t), Method: http.MethodPut, - Path: "/apisix/admin/routes/r1", + Path: "/apisix/admin/routes/r2", Body: `{ "uri": "/server_port", - "upstream_id": "1" + "service_id": "200" }`, Headers: map[string]string{"Authorization": token}, ExpectStatus: http.StatusOK, Sleep: sleepTime, }, + { + caseDesc: "hit the route just created", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/server_port", + ExpectStatus: http.StatusOK, + ExpectBody: "1982", + Sleep: sleepTime, + }, + { + caseDesc: "hit the route just created", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/server_port", + ExpectStatus: http.StatusOK, + ExpectBody: "1981", + Sleep: sleepTime, + }, { caseDesc: "hit the route just created", Object: APISIXExpect(t), @@ -112,34 +165,75 @@ func TestRoute_Create_Upstream(t *testing.T) { } } -func TestRoute_Create_Service(t *testing.T) { +func TestRoute_Delete_Service(t *testing.T) { tests := []HttpTestCase{ { - caseDesc: "create service", + caseDesc: "delete route", + Object: MangerApiExpect(t), + Method: http.MethodDelete, + Path: "/apisix/admin/routes/r2", + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "remove service", + Object: MangerApiExpect(t), + Method: http.MethodDelete, + Path: "/apisix/admin/services/200", + Headers: map[string]string{"Authorization": token}, + ExpectStatus: http.StatusOK, + }, + { + caseDesc: "hit deleted route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/server_port", + ExpectStatus: http.StatusNotFound, + }, + } + for _, tc := range tests { + testCaseCheck(tc) + } +} + +func TestRoute_Create_Upstream(t *testing.T) { + tests := []HttpTestCase{ + { + caseDesc: "create upstream", Object: MangerApiExpect(t), Method: http.MethodPut, - Path: "/apisix/admin/services/200", + Path: "/apisix/admin/upstreams/1", Body: `{ - "upstream": { - "type": "roundrobin", - "nodes": [{ + "nodes": [ + { "host": "172.16.238.20", "port": 1980, "weight": 1 - }] - } + }, + { + "host": "172.16.238.20", + "port": 1981, + "weight": 1 + }, + { + "host": "172.16.238.20", + "port": 1982, + "weight": 1 + } + ], + "type": "roundrobin" }`, Headers: map[string]string{"Authorization": token}, ExpectStatus: http.StatusOK, }, { - caseDesc: "create route using the service just created", + caseDesc: "create route using the upstream just created", Object: MangerApiExpect(t), Method: http.MethodPut, - Path: "/apisix/admin/routes/r2", + Path: "/apisix/admin/routes/r1", Body: `{ - "uri": "/hello", - "service_id": "200" + "uri": "/server_port", + "upstream_id": "1" }`, Headers: map[string]string{"Authorization": token}, ExpectStatus: http.StatusOK, @@ -149,34 +243,28 @@ func TestRoute_Create_Service(t *testing.T) { caseDesc: "hit the route just created", Object: APISIXExpect(t), Method: http.MethodGet, - Path: "/hello", + Path: "/server_port", ExpectStatus: http.StatusOK, - ExpectBody: "hello world\n", + ExpectBody: "1982", Sleep: sleepTime, }, - } - for _, tc := range tests { - testCaseCheck(tc) - } -} - -func TestRoute_Delete_Upstream(t *testing.T) { - tests := []HttpTestCase{ { - caseDesc: "delete route", - Object: MangerApiExpect(t), - Method: http.MethodDelete, - Path: "/apisix/admin/routes/r1", - Headers: map[string]string{"Authorization": token}, + caseDesc: "hit the route just created", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/server_port", ExpectStatus: http.StatusOK, + ExpectBody: "1981", + Sleep: sleepTime, }, { - caseDesc: "remove upstream", - Object: MangerApiExpect(t), - Method: http.MethodDelete, - Path: "/apisix/admin/upstreams/1", - Headers: map[string]string{"Authorization": token}, + caseDesc: "hit the route just created", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/server_port", ExpectStatus: http.StatusOK, + ExpectBody: "1980", + Sleep: sleepTime, }, } for _, tc := range tests { @@ -184,24 +272,31 @@ func TestRoute_Delete_Upstream(t *testing.T) { } } -func TestRoute_Delete_Service(t *testing.T) { +func TestRoute_Delete_Upstream(t *testing.T) { tests := []HttpTestCase{ { caseDesc: "delete route", Object: MangerApiExpect(t), Method: http.MethodDelete, - Path: "/apisix/admin/routes/r2", + Path: "/apisix/admin/routes/r1", Headers: map[string]string{"Authorization": token}, ExpectStatus: http.StatusOK, }, { - caseDesc: "remove service", + caseDesc: "remove upstream", Object: MangerApiExpect(t), Method: http.MethodDelete, - Path: "/apisix/admin/services/200", + Path: "/apisix/admin/upstreams/1", Headers: map[string]string{"Authorization": token}, ExpectStatus: http.StatusOK, }, + { + caseDesc: "hit deleted route", + Object: APISIXExpect(t), + Method: http.MethodGet, + Path: "/server_port", + ExpectStatus: http.StatusNotFound, + }, } for _, tc := range tests { testCaseCheck(tc) From ea8522c9cd05476d876c93d3b8a0e216ca68dc59 Mon Sep 17 00:00:00 2001 From: EnableAsync <43645467+EnableAsync@users.noreply.github.com> Date: Tue, 17 Nov 2020 18:25:13 +0800 Subject: [PATCH 9/9] test: fix test conflict --- api/test/e2e/route_service_upstream_test.go | 44 ++++++--------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/api/test/e2e/route_service_upstream_test.go b/api/test/e2e/route_service_upstream_test.go index d4a5289cbe..8bd2379f0d 100644 --- a/api/test/e2e/route_service_upstream_test.go +++ b/api/test/e2e/route_service_upstream_test.go @@ -95,7 +95,6 @@ func TestRoute_Create_Service(t *testing.T) { Method: http.MethodPut, Path: "/apisix/admin/services/200", Body: `{ -<<<<<<< HEAD "upstream": { "type": "roundrobin", "nodes": [ @@ -115,15 +114,7 @@ func TestRoute_Create_Service(t *testing.T) { "weight": 1 } ] - } -======= - "nodes": [{ - "host": "172.16.238.20", - "port": 1980, - "weight": 1 - }], - "type": "roundrobin" ->>>>>>> feffc04b3959d80081d15bbaef3706bb1a27a57f + } }`, Headers: map[string]string{"Authorization": token}, ExpectStatus: http.StatusOK, @@ -213,35 +204,24 @@ func TestRoute_Create_Upstream(t *testing.T) { Method: http.MethodPut, Path: "/apisix/admin/upstreams/1", Body: `{ -<<<<<<< HEAD - "nodes": [ + "nodes": [ { - "host": "172.16.238.20", - "port": 1980, - "weight": 1 + "host": "172.16.238.20", + "port": 1980, + "weight": 1 }, { - "host": "172.16.238.20", - "port": 1981, - "weight": 1 + "host": "172.16.238.20", + "port": 1981, + "weight": 1 }, { - "host": "172.16.238.20", - "port": 1982, - "weight": 1 - } - ], - "type": "roundrobin" -======= - "upstream": { - "type": "roundrobin", - "nodes": [{ "host": "172.16.238.20", - "port": 1980, + "port": 1982, "weight": 1 - }] - } ->>>>>>> feffc04b3959d80081d15bbaef3706bb1a27a57f + } + ], + "type": "roundrobin" }`, Headers: map[string]string{"Authorization": token}, ExpectStatus: http.StatusOK,