You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/03/17 15:53:59 UTC
[GitHub] [apisix-dashboard] starsz commented on a change in pull request #1599: feat: check if the upstream is using by route when deleting
starsz commented on a change in pull request #1599:
URL: https://github.com/apache/apisix-dashboard/pull/1599#discussion_r596155150
##########
File path: api/test/e2enew/upstream/upstream_test.go
##########
@@ -723,3 +724,126 @@ var _ = ginkgo.Describe("Upstream update use patch method", func() {
})
})
})
+
+var _ = ginkgo.Describe("test upstream delete (route is using)", func() {
+ table.DescribeTable("test upstream delete",
+ func(tc base.HttpTestCase) {
+ base.RunTestCase(tc)
+ },
+ table.Entry("create upstream without plugin", base.HttpTestCase{
+ Desc: "create upstream without plugin",
+ Object: base.ManagerApiExpect(),
+ Method: http.MethodPut,
+ Path: "/apisix/admin/upstreams/u1",
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ Body: `{
+ "nodes": {
+ "172.16.238.20:1980": 1
+ },
+ "type": "roundrobin"
+ }`,
+ ExpectStatus: http.StatusOK,
+ ExpectBody: "\"id\":\"u1\"",
+ }),
+ table.Entry("create route use upstream r1", base.HttpTestCase{
+ Desc: "create route use upstream u1",
+ Object: base.ManagerApiExpect(),
+ Method: http.MethodPut,
+ Path: "/apisix/admin/routes/r1",
+ Body: `{
+ "id": "r1",
+ "name": "route1",
+ "uri": "/hello",
+ "upstream_id": "u1"
+ }`,
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ ExpectStatus: http.StatusOK,
+ ExpectBody: "\"upstream_id\":\"u1\"",
+ }),
+ table.Entry("delete upstream failed", base.HttpTestCase{
+ Desc: "delete upstream failed",
+ Object: base.ManagerApiExpect(),
+ Method: http.MethodDelete,
+ Path: "/apisix/admin/upstreams/u1",
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ ExpectStatus: http.StatusBadRequest,
+ ExpectBody: "route: route1 is using this upstream",
+ }),
+ table.Entry("delete route first", base.HttpTestCase{
+ Desc: "delete route first",
+ Object: base.ManagerApiExpect(),
+ Method: http.MethodDelete,
+ Path: "/apisix/admin/routes/r1",
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ ExpectStatus: http.StatusOK,
+ }),
+ table.Entry("delete upstream success", base.HttpTestCase{
+ Desc: "delete upstream success",
+ Object: base.ManagerApiExpect(),
+ Method: http.MethodDelete,
+ Path: "/apisix/admin/upstreams/u1",
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ ExpectStatus: http.StatusOK,
+ }))
+})
+
+var _ = ginkgo.Describe("test upstream delete (service is using)", func() {
+ table.DescribeTable("test upstream delete",
+ func(tc base.HttpTestCase) {
+ base.RunTestCase(tc)
+ },
+ table.Entry("create upstream without plugin", base.HttpTestCase{
+ Desc: "create upstream without plugin",
+ Object: base.ManagerApiExpect(),
+ Method: http.MethodPut,
+ Path: "/apisix/admin/upstreams/u1",
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ Body: `{
+ "nodes": {
+ "172.16.238.20:1980": 1
+ },
+ "type": "roundrobin"
+ }`,
+ ExpectStatus: http.StatusOK,
+ ExpectBody: "\"id\":\"u1\"",
+ }),
+ table.Entry("create service use upstream r1", base.HttpTestCase{
+ Desc: "create service use upstream r1",
+ Object: base.ManagerApiExpect(),
+ Method: http.MethodPut,
+ Path: "/apisix/admin/services/s1",
+ Body: `{
+ "id": "s1",
+ "name": "service1",
+ "upstream_id": "u1"
+ }`,
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ ExpectStatus: http.StatusOK,
+ ExpectBody: "\"upstream_id\":\"u1\"",
+ }),
+ table.Entry("delete upstream failed", base.HttpTestCase{
+ Desc: "delete upstream failed",
+ Object: base.ManagerApiExpect(),
+ Method: http.MethodDelete,
+ Path: "/apisix/admin/upstreams/u1",
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ ExpectStatus: http.StatusBadRequest,
+ ExpectBody: "service: service1 is using this upstream",
+ }),
+ table.Entry("delete service first", base.HttpTestCase{
+ Desc: "delete service first",
+ Object: base.ManagerApiExpect(),
+ Method: http.MethodDelete,
+ Path: "/apisix/admin/services/s1",
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ ExpectStatus: http.StatusOK,
+ }),
+ table.Entry("delete upstream success", base.HttpTestCase{
+ Desc: "delete upstream success",
+ Object: base.ManagerApiExpect(),
+ Method: http.MethodDelete,
+ Path: "/apisix/admin/upstreams/u1",
+ Headers: map[string]string{"Authorization": base.GetToken()},
+ ExpectStatus: http.StatusOK,
+ }))
Review comment:
Yes, added.
----------------------------------------------------------------
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:
users@infra.apache.org