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 2022/07/12 06:22:20 UTC

[GitHub] [apisix-dashboard] juzhiyuan commented on a diff in pull request #2512: test: move consumer unit cases to e2e

juzhiyuan commented on code in PR #2512:
URL: https://github.com/apache/apisix-dashboard/pull/2512#discussion_r918588851


##########
api/test/e2e/consumer/consumer_test.go:
##########
@@ -44,57 +59,92 @@ var _ = Describe("Consumer", func() {
 						"key": "remote_addr",
 						"policy": "local"
 					}
-				},
-				"desc": "test description"
+				}
 			}`,
 			Headers:      map[string]string{"Authorization": base.GetToken()},
 			ExpectStatus: http.StatusOK,
-			ExpectBody:   []string{"\"code\":0", "\"username\":\"consumer_1\""},
+			ExpectBody:   `"username":"consumer_1"`,
 		}),
-		Entry("get consumer #1", base.HttpTestCase{
+		Entry("Get consumer (Exist)", base.HttpTestCase{
 			Object:       base.ManagerApiExpect(),
 			Method:       http.MethodGet,
 			Path:         "/apisix/admin/consumers/consumer_1",
 			Headers:      map[string]string{"Authorization": base.GetToken()},
 			ExpectStatus: http.StatusOK,
-			ExpectBody:   "\"username\":\"consumer_1\"",
+			ExpectBody:   `"username":"consumer_1"`,
 		}),
-		Entry("update consumer", base.HttpTestCase{
+		Entry("List consumer (1 item)", base.HttpTestCase{
+			Object:       base.ManagerApiExpect(),
+			Method:       http.MethodGet,
+			Path:         "/apisix/admin/consumers",
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   `"total_size":1`,
+		}),
+		Entry("Create consumer #2", base.HttpTestCase{
 			Object: base.ManagerApiExpect(),
 			Method: http.MethodPut,
-			Path:   "/apisix/admin/consumers/consumer_1",
+			Path:   "/apisix/admin/consumers",
 			Body: `{
-				"username": "consumer_1",
+				"username": "consumer_2",
 				"plugins": {
 					"limit-count": {
 						"count": 2,
 						"time_window": 60,
-						"rejected_code": 504,
+						"rejected_code": 503,
 						"key": "remote_addr",
 						"policy": "local"
 					}
-				},
-				"desc": "test description"
+				}
 			}`,
 			Headers:      map[string]string{"Authorization": base.GetToken()},
 			ExpectStatus: http.StatusOK,
-			ExpectBody:   []string{"\"code\":0", "\"username\":\"consumer_1\"", "\"rejected_code\":504"},
+			ExpectBody:   `"username":"consumer_2"`,
 		}),
-		Entry("get consumer #2", base.HttpTestCase{
+		Entry("List consumer (2 item)", base.HttpTestCase{
 			Object:       base.ManagerApiExpect(),
 			Method:       http.MethodGet,
-			Path:         "/apisix/admin/consumers/consumer_1",
+			Path:         "/apisix/admin/consumers",
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   `"total_size":2`,
+		}),
+		Entry("List consumer (Paginate)", base.HttpTestCase{
+			Object:       base.ManagerApiExpect(),
+			Method:       http.MethodGet,
+			Path:         "/apisix/admin/consumers",
+			Query:        "page=2&page_size=1",
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   `"username":"consumer_2"`,
+		}),
+		Entry("Update consumer", base.HttpTestCase{
+			Object: base.ManagerApiExpect(),
+			Method: http.MethodPut,
+			Path:   "/apisix/admin/consumers/consumer_1",
+			Body: `{
+				"username": "consumer_1",
+				"plugins": {
+					"limit-count": {
+						"count": 2,
+						"time_window": 60,
+						"rejected_code": 504,
+						"key": "remote_addr",
+						"policy": "local"
+					}
+				}
+			}`,
 			Headers:      map[string]string{"Authorization": base.GetToken()},
 			ExpectStatus: http.StatusOK,
-			ExpectBody:   "\"rejected_code\":504",
+			ExpectBody:   []string{`"code":0`, `"username":"consumer_1"`, `"rejected_code":504`},
 		}),
-		Entry("delete consumer", base.HttpTestCase{
+		Entry("Batch Delete consumer", base.HttpTestCase{
 			Object:       base.ManagerApiExpect(),
 			Method:       http.MethodDelete,
-			Path:         "/apisix/admin/consumers/consumer_1",
+			Path:         "/apisix/admin/consumers/consumer_1,consumer_2",

Review Comment:
   🤔 A little wired. One question: what will happen if deleting one of them failed?



##########
api/test/e2e/consumer/consumer_test.go:
##########
@@ -44,57 +59,92 @@ var _ = Describe("Consumer", func() {
 						"key": "remote_addr",
 						"policy": "local"
 					}
-				},
-				"desc": "test description"
+				}
 			}`,
 			Headers:      map[string]string{"Authorization": base.GetToken()},
 			ExpectStatus: http.StatusOK,
-			ExpectBody:   []string{"\"code\":0", "\"username\":\"consumer_1\""},
+			ExpectBody:   `"username":"consumer_1"`,
 		}),
-		Entry("get consumer #1", base.HttpTestCase{
+		Entry("Get consumer (Exist)", base.HttpTestCase{
 			Object:       base.ManagerApiExpect(),
 			Method:       http.MethodGet,
 			Path:         "/apisix/admin/consumers/consumer_1",
 			Headers:      map[string]string{"Authorization": base.GetToken()},
 			ExpectStatus: http.StatusOK,
-			ExpectBody:   "\"username\":\"consumer_1\"",
+			ExpectBody:   `"username":"consumer_1"`,
 		}),
-		Entry("update consumer", base.HttpTestCase{
+		Entry("List consumer (1 item)", base.HttpTestCase{
+			Object:       base.ManagerApiExpect(),
+			Method:       http.MethodGet,
+			Path:         "/apisix/admin/consumers",
+			Headers:      map[string]string{"Authorization": base.GetToken()},
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   `"total_size":1`,
+		}),
+		Entry("Create consumer #2", base.HttpTestCase{
 			Object: base.ManagerApiExpect(),
 			Method: http.MethodPut,
-			Path:   "/apisix/admin/consumers/consumer_1",
+			Path:   "/apisix/admin/consumers",
 			Body: `{
-				"username": "consumer_1",
+				"username": "consumer_2",
 				"plugins": {
 					"limit-count": {
 						"count": 2,
 						"time_window": 60,
-						"rejected_code": 504,
+						"rejected_code": 503,
 						"key": "remote_addr",
 						"policy": "local"
 					}
-				},
-				"desc": "test description"
+				}
 			}`,
 			Headers:      map[string]string{"Authorization": base.GetToken()},
 			ExpectStatus: http.StatusOK,
-			ExpectBody:   []string{"\"code\":0", "\"username\":\"consumer_1\"", "\"rejected_code\":504"},
+			ExpectBody:   `"username":"consumer_2"`,
 		}),
-		Entry("get consumer #2", base.HttpTestCase{
+		Entry("List consumer (2 item)", base.HttpTestCase{

Review Comment:
   ```suggestion
   		Entry("List consumer (2 items)", base.HttpTestCase{
   ```



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

To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org