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 2020/12/01 06:54:35 UTC

[GitHub] [apisix-dashboard] membphis commented on a change in pull request #880: test: add consumer with incorrect input ( E2E )

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



##########
File path: api/test/e2e/consumer_test.go
##########
@@ -131,3 +136,219 @@ func TestConsumer_with_key_auth(t *testing.T) {
 		testCaseCheck(tc)
 	}
 }
+
+func TestConsumer_with_notexist_plugin(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer with not exist plugin",
+			Object:   ManagerApiExpect(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:   "schema validate failed: schema not found, path: plugins.key-authaa",
+		},
+		{
+			caseDesc:     "verify the consumer",
+			Object:       ManagerApiExpect(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:   ManagerApiExpect(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:       ManagerApiExpect(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:   ManagerApiExpect(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:       ManagerApiExpect(t),
+			Method:       http.MethodDelete,
+			Path:         "/apisix/admin/consumers/jack",
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "delete the route",
+			Object:       ManagerApiExpect(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) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create the consumer",
+			Object:   ManagerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				 "username":"jack",
+				 "desc": "new consumer"
+			 }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime,
+		},
+	}
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+
+	basepath := "http://127.0.0.1:8080/apisix/admin/consumers"
+	time.Sleep(time.Duration(1) * time.Second)
+
+	//get the consumer, save createtime and updatetime
+	request, _ := http.NewRequest("GET", basepath+"/jack", nil)
+	request.Header.Add("Authorization", token)
+	resp, _ := http.DefaultClient.Do(request)
+	respBody, _ := ioutil.ReadAll(resp.Body)
+	createtime := gjson.Get(string(respBody), "data.create_time")
+	updatetime := gjson.Get(string(respBody), "data.update_time")
+
+	//wait 1 second so the update_time should be different
+	time.Sleep(time.Duration(1) * time.Second)
+
+	tests = []HttpTestCase{
+		{
+			caseDesc: "update the consumer",
+			Object:   ManagerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				 "username":"jack",
+				 "desc": "updated consumer"
+			 }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+
+	//get the consumer

Review comment:
       we should always add one space after `//`




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