You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ju...@apache.org on 2020/07/12 07:45:48 UTC
[incubator-apisix-dashboard] branch master updated: test: add e2e
test for ssl and consumer (#309)
This is an automated email from the ASF dual-hosted git repository.
juzhiyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 853d5f3 test: add e2e test for ssl and consumer (#309)
853d5f3 is described below
commit 853d5f3c9cffbe67b909fc3b93b18a3e0890feb7
Author: nic-chen <33...@users.noreply.github.com>
AuthorDate: Sun Jul 12 15:45:37 2020 +0800
test: add e2e test for ssl and consumer (#309)
* test: add e2e test for ssl and consumer
* fix: change assert to avoid the mutual influence of route and service test
* remove useless code
---
api/go.mod | 3 +-
api/go.sum | 6 +++
api/route/base_test.go | 52 ++++++++++++++++++++++++
api/route/consumer.go | 47 ++++++++++-----------
api/route/consumer_test.go | 97 ++++++++++++++++++++++++++++++++++++++++++++
api/route/ssl.go | 69 ++++++++++++++-----------------
api/route/ssl_test.go | 41 +++++++++++++++++++
api/route/zclear_test.go | 37 +++++++++++++++++
api/service/consumer_test.go | 4 +-
api/service/ssl_test.go | 4 +-
10 files changed, 291 insertions(+), 69 deletions(-)
diff --git a/api/go.mod b/api/go.mod
index 45372ec..ab07faa 100644
--- a/api/go.mod
+++ b/api/go.mod
@@ -3,13 +3,14 @@ module github.com/apisix/manager-api
go 1.13
require (
+ github.com/api7/apitest v1.4.9
github.com/gin-contrib/pprof v1.3.0
github.com/gin-gonic/gin v1.6.3
github.com/go-sql-driver/mysql v1.5.0
github.com/jinzhu/gorm v1.9.12
github.com/satori/go.uuid v1.2.0
github.com/sirupsen/logrus v1.6.0
- github.com/stretchr/testify v1.4.0
+ github.com/stretchr/testify v1.6.1
github.com/tidwall/gjson v1.6.0
gopkg.in/resty.v1 v1.12.0
)
diff --git a/api/go.sum b/api/go.sum
index 9e3e3e3..1daa324 100644
--- a/api/go.sum
+++ b/api/go.sum
@@ -1,3 +1,5 @@
+github.com/api7/apitest v1.4.9 h1:FYTUQJ1hgeB9UvMFif1jjbfiA+XqHPEBfsjhDskytA8=
+github.com/api7/apitest v1.4.9/go.mod h1:YZruZ+jDMFL6rNgMWiuhwCTugNN0mJkLCYCHG3ICYlE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -55,6 +57,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
+github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
+github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc=
github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
@@ -87,3 +91,5 @@ gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/api/route/base_test.go b/api/route/base_test.go
new file mode 100644
index 0000000..7135db0
--- /dev/null
+++ b/api/route/base_test.go
@@ -0,0 +1,52 @@
+/*
+ * 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 (
+ "github.com/api7/apitest"
+ "github.com/gin-gonic/gin"
+
+ "github.com/apisix/manager-api/conf"
+ "github.com/apisix/manager-api/filter"
+)
+
+var handler *apitest.APITest
+
+var (
+ r = gin.New()
+ uriPrefix = "/apisix/admin"
+)
+
+func init() {
+ //init mysql connect
+ conf.InitializeMysql()
+
+ //filters
+ r.Use(
+ filter.CORS(),
+ filter.RequestId(),
+ filter.RequestLogHandler(),
+ filter.RecoverHandler())
+
+ handler = apitest.New().
+ Handler(AppendHealthCheck(r)).
+ Handler(AppendRoute(r)).
+ Handler(AppendSsl(r)).
+ Handler(AppendPlugin(r)).
+ Handler(AppendConsumer(r)).
+ Handler(AppendUpstream(r))
+}
diff --git a/api/route/consumer.go b/api/route/consumer.go
index 8c442b6..3f0bfa1 100644
--- a/api/route/consumer.go
+++ b/api/route/consumer.go
@@ -39,6 +39,22 @@ func AppendConsumer(r *gin.Engine) *gin.Engine {
return r
}
+func handleServiceError(c *gin.Context, requestId interface{}, err error) {
+ if httpError, ok := err.(*errno.HttpError); ok {
+ logger.WithField(conf.RequestId, requestId).Error(err)
+ c.AbortWithStatusJSON(httpError.Code, httpError.Msg)
+ return
+ }
+
+ e := err.(*errno.ManagerError)
+ status := http.StatusInternalServerError
+ if e.Status > 0 {
+ status = e.Status
+ }
+ logger.WithField(conf.RequestId, requestId).Error(e.ErrorDetail())
+ c.AbortWithStatusJSON(status, e.Response())
+}
+
func consumerList(c *gin.Context) {
requestId, _ := c.Get("X-Request-Id")
size, _ := strconv.Atoi(c.DefaultQuery("size", "10"))
@@ -49,8 +65,7 @@ func consumerList(c *gin.Context) {
count, list, err := service.ConsumerList(page, size, search)
if err != nil {
- logger.WithField(conf.RequestId, requestId).Error(err.(*errno.ManagerError).ErrorDetail())
- c.AbortWithStatusJSON(http.StatusInternalServerError, err.(*errno.ManagerError).Response())
+ handleServiceError(c, requestId, err)
return
}
@@ -66,8 +81,7 @@ func consumerItem(c *gin.Context) {
consumer, err := service.ConsumerItem(id)
if err != nil {
- logger.WithField(conf.RequestId, requestId).Error(err.(*errno.ManagerError).ErrorDetail())
- c.AbortWithStatusJSON(http.StatusInternalServerError, err.(*errno.ManagerError).Response())
+ handleServiceError(c, requestId, err)
return
}
@@ -88,13 +102,7 @@ func consumerCreate(c *gin.Context) {
}
if err := service.ConsumerCreate(param, u4.String()); err != nil {
- if httpError, ok := err.(*errno.HttpError); ok {
- logger.WithField(conf.RequestId, requestId).Error(err)
- c.AbortWithStatusJSON(httpError.Code, httpError.Msg)
- return
- }
- logger.WithField(conf.RequestId, requestId).Error(err.(*errno.ManagerError).ErrorDetail())
- c.AbortWithStatusJSON(http.StatusInternalServerError, err.(*errno.ManagerError).Response())
+ handleServiceError(c, requestId, err)
return
}
@@ -115,13 +123,7 @@ func consumerUpdate(c *gin.Context) {
}
if err := service.ConsumerUpdate(param, id); err != nil {
- if httpError, ok := err.(*errno.HttpError); ok {
- logger.WithField(conf.RequestId, requestId).Error(err)
- c.AbortWithStatusJSON(httpError.Code, httpError.Msg)
- return
- }
- logger.WithField(conf.RequestId, requestId).Error(err.(*errno.ManagerError).ErrorDetail())
- c.AbortWithStatusJSON(http.StatusInternalServerError, err.(*errno.ManagerError).Response())
+ handleServiceError(c, requestId, err)
return
}
@@ -133,14 +135,7 @@ func consumerDelete(c *gin.Context) {
id := c.Param("id")
if err := service.ConsumerDelete(id); err != nil {
- if httpError, ok := err.(*errno.HttpError); ok {
- logger.WithField(conf.RequestId, requestId).Error(err)
- c.AbortWithStatusJSON(httpError.Code, httpError.Msg)
- return
- }
-
- logger.WithField(conf.RequestId, requestId).Error(err.(*errno.ManagerError).ErrorDetail())
- c.AbortWithStatusJSON(http.StatusInternalServerError, err.(*errno.ManagerError).Response())
+ handleServiceError(c, requestId, err)
return
}
diff --git a/api/route/consumer_test.go b/api/route/consumer_test.go
new file mode 100644
index 0000000..60066bb
--- /dev/null
+++ b/api/route/consumer_test.go
@@ -0,0 +1,97 @@
+/*
+ * 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"
+ "testing"
+
+ "github.com/apisix/manager-api/service"
+)
+
+func TestConsumer(t *testing.T) {
+ // create ok
+ handler.
+ Post(uriPrefix + "/consumers").
+ JSON(`{
+ "username": "e2e_test_consumer1",
+ "plugins": {
+ "limit-count": {
+ "count": 2,
+ "time_window": 60,
+ "rejected_code": 503,
+ "key": "remote_addr"
+ },
+ "basic-auth": {
+ "username": "foo",
+ "password": "bar"
+ }
+ },
+ "desc": "test description"
+ }`).
+ Expect(t).
+ Status(http.StatusOK).
+ End()
+
+ c1, _ := service.GetConsumerByUserName("e2e_test_consumer1")
+
+ //update ok
+ handler.
+ Put(uriPrefix + "/consumers/" + c1.ID.String()).
+ JSON(`{
+ "username": "e2e_test_consumer1",
+ "plugins": {
+ "limit-count": {
+ "count": 2,
+ "time_window": 60,
+ "rejected_code": 503,
+ "key": "remote_addr"
+ },
+ "basic-auth": {
+ "username": "foo",
+ "password": "bar"
+ }
+ },
+ "desc": "test desc"
+ }`).
+ Expect(t).
+ Status(http.StatusOK).
+ End()
+
+ // duplicate username
+ handler.
+ Post(uriPrefix + "/consumers").
+ JSON(`{
+ "username": "e2e_test_consumer1",
+ "plugins": {
+ "limit-count": {
+ "count": 2,
+ "time_window": 60,
+ "rejected_code": 503,
+ "key": "remote_addr"
+ },
+ "basic-auth": {
+ "username": "foo",
+ "password": "bar"
+ }
+ },
+ "desc": "test description"
+ }`).
+ Expect(t).
+ Status(http.StatusBadRequest).
+ End()
+}
diff --git a/api/route/ssl.go b/api/route/ssl.go
index 7b62b49..d962be8 100644
--- a/api/route/ssl.go
+++ b/api/route/ssl.go
@@ -30,6 +30,7 @@ import (
func AppendSsl(r *gin.Engine) *gin.Engine {
r.POST("/apisix/admin/check_ssl_cert", sslCheck)
+ r.POST("/apisix/admin/check_ssl_exists", hostCheck)
r.GET("/apisix/admin/ssls", sslList)
r.POST("/apisix/admin/ssls", sslCreate)
@@ -48,14 +49,14 @@ func sslList(c *gin.Context) {
status, _ := strconv.Atoi(c.DefaultQuery("status", "-1"))
expireStart, _ := strconv.Atoi(c.DefaultQuery("expire_start", "-1"))
expireEnd, _ := strconv.Atoi(c.DefaultQuery("expire_end", "-1"))
+ sortType := c.DefaultQuery("sort_type", "desc")
sni := c.DefaultQuery("sni", "")
- count, list, err := service.SslList(page, size, status, expireStart, expireEnd, sni)
+ count, list, err := service.SslList(page, size, status, expireStart, expireEnd, sni, sortType)
if err != nil {
- logger.WithField(conf.RequestId, requestId).Error(err.(*errno.ManagerError).ErrorDetail())
- c.AbortWithStatusJSON(http.StatusInternalServerError, err.(*errno.ManagerError).Response())
+ handleServiceError(c, requestId, err)
return
}
@@ -71,8 +72,7 @@ func sslItem(c *gin.Context) {
ssl, err := service.SslItem(id)
if err != nil {
- logger.WithField(conf.RequestId, requestId).Error(err.(*errno.ManagerError).ErrorDetail())
- c.AbortWithStatusJSON(http.StatusInternalServerError, err.(*errno.ManagerError).Response())
+ handleServiceError(c, requestId, err)
return
}
@@ -92,8 +92,7 @@ func sslCheck(c *gin.Context) {
ssl, err := service.SslCheck(param)
if err != nil {
- logger.WithField(conf.RequestId, requestId).Error(err.(*errno.ManagerError).ErrorDetail())
- c.AbortWithStatusJSON(http.StatusInternalServerError, err.(*errno.ManagerError).Response())
+ handleServiceError(c, requestId, err)
return
}
@@ -116,13 +115,7 @@ func sslCreate(c *gin.Context) {
}
if err := service.SslCreate(param, u4.String()); err != nil {
- if httpError, ok := err.(*errno.HttpError); ok {
- logger.WithField(conf.RequestId, requestId).Error(err)
- c.AbortWithStatusJSON(httpError.Code, httpError.Msg)
- return
- }
- logger.WithField(conf.RequestId, requestId).Error(err.(*errno.ManagerError).ErrorDetail())
- c.AbortWithStatusJSON(http.StatusInternalServerError, err.(*errno.ManagerError).Response())
+ handleServiceError(c, requestId, err)
return
}
@@ -132,7 +125,6 @@ func sslCreate(c *gin.Context) {
func sslUpdate(c *gin.Context) {
requestId, _ := c.Get("X-Request-Id")
param, exist := c.Get("requestBody")
-
id := c.Param("id")
if !exist || len(param.([]byte)) < 1 {
@@ -143,13 +135,7 @@ func sslUpdate(c *gin.Context) {
}
if err := service.SslUpdate(param, id); err != nil {
- if httpError, ok := err.(*errno.HttpError); ok {
- logger.WithField(conf.RequestId, requestId).Error(err)
- c.AbortWithStatusJSON(httpError.Code, httpError.Msg)
- return
- }
- logger.WithField(conf.RequestId, requestId).Error(err.(*errno.ManagerError).ErrorDetail())
- c.AbortWithStatusJSON(http.StatusInternalServerError, err.(*errno.ManagerError).Response())
+ handleServiceError(c, requestId, err)
return
}
@@ -170,14 +156,7 @@ func sslPatch(c *gin.Context) {
}
if err := service.SslPatch(param, id); err != nil {
- if httpError, ok := err.(*errno.HttpError); ok {
- logger.WithField(conf.RequestId, requestId).Error(err)
- c.AbortWithStatusJSON(httpError.Code, httpError.Msg)
- return
- }
-
- logger.WithField(conf.RequestId, requestId).Error(err.(*errno.ManagerError).ErrorDetail())
- c.AbortWithStatusJSON(http.StatusInternalServerError, err.(*errno.ManagerError).Response())
+ handleServiceError(c, requestId, err)
return
}
@@ -189,16 +168,30 @@ func sslDelete(c *gin.Context) {
id := c.Param("id")
if err := service.SslDelete(id); err != nil {
- if httpError, ok := err.(*errno.HttpError); ok {
- logger.WithField(conf.RequestId, requestId).Error(err)
- c.AbortWithStatusJSON(httpError.Code, httpError.Msg)
- return
- }
-
- logger.WithField(conf.RequestId, requestId).Error(err.(*errno.ManagerError).ErrorDetail())
- c.AbortWithStatusJSON(http.StatusInternalServerError, err.(*errno.ManagerError).Response())
+ handleServiceError(c, requestId, err)
return
}
c.JSON(http.StatusOK, errno.Succeed())
}
+
+func hostCheck(c *gin.Context) {
+ requestId, _ := c.Get("X-Request-Id")
+ param, exist := c.Get("requestBody")
+
+ if !exist || len(param.([]byte)) < 1 {
+ err := errno.New(errno.InvalidParam)
+ logger.WithField(conf.RequestId, requestId).Error(err.ErrorDetail())
+ c.AbortWithStatusJSON(http.StatusBadRequest, err.Response())
+ return
+ }
+
+ err := service.CheckSniExists(param)
+ if err != nil {
+ handleServiceError(c, requestId, err)
+ return
+ }
+
+ c.JSON(http.StatusOK, errno.Succeed())
+
+}
diff --git a/api/route/ssl_test.go b/api/route/ssl_test.go
new file mode 100644
index 0000000..a4a2308
--- /dev/null
+++ b/api/route/ssl_test.go
@@ -0,0 +1,41 @@
+package route
+
+import (
+ "net/http"
+ "testing"
+)
+
+func TestSslCreate(t *testing.T) {
+ // ok
+ handler.
+ Post(uriPrefix + "/ssls").
+ JSON(`{
+ "key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDGO0J9xrOcmvgh\npkqHIYHCw35FTfIT5uXOSzdF49M2ZAKBQwFG0ovYT8bc0glNLB+hpDhJPL531qSP\nl1ZOe0W1ofP1u0T5Zzc9Rub/kn7RMPq0BsSC6J3rF+rQEwh1PM8qUuD8DxZ7jaOL\niMNL6SyuZIPsS1kPPBtsioukdo666tbjNMixhQbI9Wpg55abdXRFh3i7Zu/9siF1\njCGcsskjOaUOY4sYQ3i5WU/HIIRhA82XuIL+Sxd32P8bKi2UT1sqFXRjAVR7KRWo\nIVvkmSLoZb9ucV6MsccDrRYBf6rLbI1tFj9l2rY6GTFlT+6z7K/ZI60DGi/hsBfl\nDeEQ5WuxAgMBAAECggEAVHQQyucpxHGdfzCKlfGnh+Oj20Du/p2jkHUp [...]
+ "cert": "-----BEGIN CERTIFICATE-----\nMIIEVzCCAr+gAwIBAgIQITiNM7xmudhg3pK85KDwLDANBgkqhkiG9w0BAQsFADB/\nMR4wHAYDVQQKExVta2NlcnQgZGV2ZWxvcG1lbnQgQ0ExKjAoBgNVBAsMIWp1bnh1\nY2hlbkBqdW54dWRlQWlyIChqdW54dSBjaGVuKTExMC8GA1UEAwwobWtjZXJ0IGp1\nbnh1Y2hlbkBqdW54dWRlQWlyIChqdW54dSBjaGVuKTAeFw0xOTA2MDEwMDAwMDBa\nFw0zMDA3MDgwNzQ4MDJaMFUxJzAlBgNVBAoTHm1rY2VydCBkZXZlbG9wbWVudCBj\nZXJ0aWZpY2F0ZTEqMCgGA1UECwwhanVueHVjaGVuQGp1bnh1ZGVBaXIgKGp1bnh1\nIGNoZW4pMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxjt [...]
+ }`).
+ Expect(t).
+ Status(http.StatusOK).
+ End()
+
+ // schema fail
+ handler.
+ Post(uriPrefix + "/ssls").
+ JSON(`{
+ "cert": "-----BEGIN CERTIFICATE-----\nMIIEVzCCAr+gAwIBAgIQITiNM7xmudhg3pK85KDwLDANBgkqhkiG9w0BAQsFADB/\nMR4wHAYDVQQKExVta2NlcnQgZGV2ZWxvcG1lbnQgQ0ExKjAoBgNVBAsMIWp1bnh1\nY2hlbkBqdW54dWRlQWlyIChqdW54dSBjaGVuKTExMC8GA1UEAwwobWtjZXJ0IGp1\nbnh1Y2hlbkBqdW54dWRlQWlyIChqdW54dSBjaGVuKTAeFw0xOTA2MDEwMDAwMDBa\nFw0zMDA3MDgwNzQ4MDJaMFUxJzAlBgNVBAoTHm1rY2VydCBkZXZlbG9wbWVudCBj\nZXJ0aWZpY2F0ZTEqMCgGA1UECwwhanVueHVjaGVuQGp1bnh1ZGVBaXIgKGp1bnh1\nIGNoZW4pMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxjt [...]
+ }`).
+ Expect(t).
+ Status(http.StatusBadRequest).
+ End()
+
+ //schema fail 2
+ handler.
+ Post(uriPrefix + "/ssls").
+ JSON(`{
+ "key": "",
+ "cert": "-----BEGIN CERTIFICATE-----\nMIIEVzCCAr+gAwIBAgIQITiNM7xmudhg3pK85KDwLDANBgkqhkiG9w0BAQsFADB/\nMR4wHAYDVQQKExVta2NlcnQgZGV2ZWxvcG1lbnQgQ0ExKjAoBgNVBAsMIWp1bnh1\nY2hlbkBqdW54dWRlQWlyIChqdW54dSBjaGVuKTExMC8GA1UEAwwobWtjZXJ0IGp1\nbnh1Y2hlbkBqdW54dWRlQWlyIChqdW54dSBjaGVuKTAeFw0xOTA2MDEwMDAwMDBa\nFw0zMDA3MDgwNzQ4MDJaMFUxJzAlBgNVBAoTHm1rY2VydCBkZXZlbG9wbWVudCBj\nZXJ0aWZpY2F0ZTEqMCgGA1UECwwhanVueHVjaGVuQGp1bnh1ZGVBaXIgKGp1bnh1\nIGNoZW4pMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxjt [...]
+ }`).
+ Expect(t).
+ Status(http.StatusBadRequest).
+ End()
+
+}
diff --git a/api/route/zclear_test.go b/api/route/zclear_test.go
new file mode 100644
index 0000000..e44101b
--- /dev/null
+++ b/api/route/zclear_test.go
@@ -0,0 +1,37 @@
+/*
+ * 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"
+ "testing"
+
+ "github.com/apisix/manager-api/service"
+)
+
+func TestClearTestData(t *testing.T) {
+ // delete consumers
+ c1, _ := service.GetConsumerByUserName("e2e_test_consumer1")
+ handler.
+ Delete(uriPrefix + "/consumers/" + c1.ID.String()).
+ Expect(t).
+ Status(http.StatusOK).
+ End()
+
+ //delete test ssl
+ service.DeleteTestSslData()
+}
diff --git a/api/service/consumer_test.go b/api/service/consumer_test.go
index ea1a077..cd0e3d9 100644
--- a/api/service/consumer_test.go
+++ b/api/service/consumer_test.go
@@ -125,8 +125,8 @@ func TestConsumerCurd(t *testing.T) {
err = ConsumerDelete(c1.String())
assert.Nil(err)
- count2, _, err := ConsumerList(2, 1, "")
- assert.Equal(count2, count-1)
+ _, err = ConsumerItem(c1.String())
+ assert.Equal(errno.DBReadError.Code, err.(*errno.ManagerError).Code)
err = ConsumerDelete(c2.String())
assert.Nil(err)
diff --git a/api/service/ssl_test.go b/api/service/ssl_test.go
index 46ecbb9..2134bb1 100644
--- a/api/service/ssl_test.go
+++ b/api/service/ssl_test.go
@@ -344,8 +344,8 @@ func TestSslCurd(t *testing.T) {
err = SslDelete(u1.String())
assert.Nil(err)
- count2, _, err := SslList(2, 1, -1, 0, 0, "", "desc")
- assert.Equal(count2, count-1)
+ _, err = SslItem(u1.String())
+ assert.Equal(errno.DBReadError.Code, err.(*errno.ManagerError).Code)
err = SslDelete(u2.String())
assert.Nil(err)