idbeta commented on a change in pull request #880:
URL: https://github.com/apache/apisix-dashboard/pull/880#discussion_r530985601



##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,220 @@
+/*
+ * 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 (
+       "fmt"
+       "io/ioutil"
+       "net/http"
+       "strings"
+       "testing"
+       "time"
+
+       "github.com/stretchr/testify/assert"
+       "github.com/tidwall/gjson"
+)
+
+func TestConsumer_with_error_plugin(t *testing.T) {
+       tests := []HttpTestCase{
+               {
+                       caseDesc: "create consumer with error key",
+                       Object:   MangerApiExpect(t),
+                       Path:     "/apisix/admin/consumers",
+                       Method:   http.MethodPut,
+                       Body: `{
+                                "username": "jack",
+                                "plugins": {
+                                        "key-authaa": {
+                                                "key": "auth-one"
+                                        }
+                                },
+                                "desc": "test description"
+                       }`,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusBadRequest,
+                       ExpectBody:   "scheme validate failed",
+               },
+               {
+                       caseDesc:     "verify the consumer",
+                       Object:       MangerApiExpect(t),
+                       Path:         "/apisix/admin/consumers/jack",
+                       Method:       http.MethodGet,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusNotFound,
+                       Sleep:        sleepTime,
+               },
+       }
+
+       for _, tc := range tests {
+               testCaseCheck(tc)
+       }
+}
+
+func TestConsumer_add_consumer_with_labels(t *testing.T) {
+       tests := []HttpTestCase{
+               {
+                       caseDesc: "create the consumer",
+                       Object:   MangerApiExpect(t),
+                       Path:     "/apisix/admin/consumers",
+                       Method:   http.MethodPut,
+                       Body: `{
+                               "username": "jack",
+                               "labels": {
+                                       "build":"16",
+                                       "env":"production",
+                                       "version":"v2"
+                               },
+                               "plugins": {
+                                       "key-auth": {
+                                               "key": "auth-two"
+                                       }
+                               },
+                           "desc": "test description"
+                       }`,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               },
+               {
+                       caseDesc:     "verify the consumer",
+                       Object:       MangerApiExpect(t),
+                       Method:       http.MethodGet,
+                       Path:         "/apisix/admin/consumers/jack",
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+                       ExpectBody:   "\"username\":\"jack\",\"desc\":\"test 
description\",\"plugins\":{\"key-auth\":{\"key\":\"auth-two\"}},\"labels\":{\"build\":\"16\",\"env\":\"production\",\"version\":\"v2\"}",
+                       Sleep:        sleepTime,
+               },
+               {
+                       caseDesc: "create the route",
+                       Object:   MangerApiExpect(t),
+                       Method:   http.MethodPut,
+                       Path:     "/apisix/admin/routes/r1",
+                       Body: `{
+                               "uri": "/hello",
+                               "plugins": {
+                                       "key-auth": {}
+                               },
+                               "upstream": {
+                                       "type": "roundrobin",
+                                       "nodes": [{
+                                               "host": "172.16.238.20",
+                                               "port": 1980,
+                                               "weight": 1
+                                       }]
+                               }
+                       }`,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               },
+               {
+                       caseDesc:     "hit the route with correct apikey",
+                       Object:       APISIXExpect(t),
+                       Method:       http.MethodGet,
+                       Path:         "/hello",
+                       Headers:      map[string]string{"apikey": "auth-two"},
+                       ExpectStatus: http.StatusOK,
+                       Sleep:        sleepTime,
+               },
+               {
+                       caseDesc:     "delete the consumer",
+                       Object:       MangerApiExpect(t),
+                       Method:       http.MethodDelete,
+                       Path:         "/apisix/admin/consumers/jack",
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               },
+               {
+                       caseDesc:     "delete the route",
+                       Object:       MangerApiExpect(t),
+                       Method:       http.MethodDelete,
+                       Path:         "/apisix/admin/routes/r1",
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               },
+       }
+
+       for _, tc := range tests {
+               testCaseCheck(tc)
+       }
+}
+
+func TestConsumer_with_createtime_updatetime(t *testing.T) {

Review comment:
       This case is used to test when the consumer is updated, create_time is 
not updated, but update_time is updated. The current framework does not support 
obtaining update_time and create_time from the response, so I use `standard 
library` and `assert` to achieve 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:
us...@infra.apache.org


Reply via email to