starsz commented on a change in pull request #1598:
URL: https://github.com/apache/apisix-dashboard/pull/1598#discussion_r596100142



##########
File path: api/test/e2enew/service/service_test.go
##########
@@ -462,3 +463,83 @@ var _ = ginkgo.Describe("service update use patch method", 
func() {
                })
        })
 })
+
+var _ = ginkgo.Describe("test service delete", func() {
+       t := ginkgo.GinkgoT()
+       var createServiceBody map[string]interface{} = map[string]interface{}{
+               "name": "testservice",
+               "upstream": map[string]interface{}{
+                       "type": "roundrobin",
+                       "nodes": []map[string]interface{}{
+                               {
+                                       "host":   base.UpstreamIp,
+                                       "port":   1980,
+                                       "weight": 1,
+                               },
+                       },
+               },
+       }
+       _createServiceBody, err := json.Marshal(createServiceBody)
+       assert.Nil(t, err)
+
+       table.DescribeTable("test service delete",
+               func(tc base.HttpTestCase) {
+                       base.RunTestCase(tc)
+               },
+               table.Entry("create service without plugin", base.HttpTestCase{
+                       Desc:         "create service without plugin",
+                       Object:       base.ManagerApiExpect(),
+                       Method:       http.MethodPut,
+                       Path:         "/apisix/admin/services/s1",
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
+                       Body:         string(_createServiceBody),
+                       ExpectStatus: http.StatusOK,
+                       ExpectBody:   
"\"name\":\"testservice\",\"upstream\":{\"nodes\":[{\"host\":\"" + 
base.UpstreamIp + "\",\"port\":1980,\"weight\":1}],\"type\":\"roundrobin\"}}",
+               }),
+               table.Entry("create route use service s1", base.HttpTestCase{
+                       Desc:   "create route use service s1",
+                       Object: base.ManagerApiExpect(),
+                       Method: http.MethodPut,
+                       Path:   "/apisix/admin/routes/r1",
+                       Body: `{
+                               "id": "r1",
+                               "name": "route1",
+                               "uri": "/hello",
+                               "upstream": {
+                                               "type": "roundrobin",
+                                               "nodes": {
+                                                               "` + 
base.UpstreamIp + `:1980": 1
+                                               }
+                               },
+                               "service_id": "s1"
+                       }`,
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
+                       ExpectStatus: http.StatusOK,
+                       ExpectBody:   "\"service_id\":\"s1\"",
+               }),
+               table.Entry("delete service failed", base.HttpTestCase{
+                       Desc:         "delete service failed",
+                       Object:       base.ManagerApiExpect(),
+                       Method:       http.MethodDelete,
+                       Path:         "/apisix/admin/services/s1",
+                       Headers:      map[string]string{"Authorization": 
base.GetToken()},
+                       ExpectStatus: http.StatusBadRequest,
+                       ExpectBody:   "route: route1 is using this service",
+               }),
+               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,
+               }),

Review comment:
       Good capture. Let me add it.




----------------------------------------------------------------
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]


Reply via email to