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/11/09 09:22:43 UTC

[GitHub] [apisix-dashboard] idbeta opened a new pull request #735: add consumer e2e test

idbeta opened a new pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735


   add consumer e2e test example
   add public method "PartialBody"
   


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



[GitHub] [apisix-dashboard] idbeta commented on a change in pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
idbeta commented on a change in pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#discussion_r519704247



##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,274 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//TEST 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 2: add consumer without username
+func TestConsumer_add_consumer_without_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusBadRequest,
+		},
+	}
+

Review comment:
       I will add test data plane here. you can see the new submit.




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



[GitHub] [apisix-dashboard] moonming commented on a change in pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
moonming commented on a change in pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#discussion_r526597432



##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,241 @@
+/*
+ * 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 (
+	"net/http"
+	"testing"
+)
+
+//CASE 1: add consumer with username
+func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+				"desc": "test description"
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+		{
+			caseDesc:     "verify route without auth",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusUnauthorized,
+			Sleep:        sleepTime,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//CASE 2: add consumer without username
+func TestConsumer_add_consumer_without_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"plugins": {
+					"key-auth": {
+						"key": "auth-new"
+					}
+				},
+			    "desc": "test description"
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusBadRequest,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-new"},
+			ExpectStatus: http.StatusUnauthorized,
+			Sleep:        sleepTime,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//CASE 3: add consumer with labels
+func TestConsumer_add_consumer_with_labels(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack2",
+				"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 consumer",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/apisix/admin/consumers/jack2",
+			Headers:      map[string]string{"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"},
+			ExpectStatus: http.StatusOK,
+			PartialBody:  "\"env\":\"production\"",
+			Sleep:        sleepTime,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-two"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//CASE 4: delete consumer
+func TestConsumer_delete_consumer(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc:     "delete consumer",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodDelete,
+			Path:         "/apisix/admin/consumers/jack",

Review comment:
       Why use admin api to do controller plane job?




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



[GitHub] [apisix-dashboard] idbeta commented on pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
idbeta commented on pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#issuecomment-724514865


   > There's a conflict here. Please fix it. @idbeta
   
   fixed.


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



[GitHub] [apisix-dashboard] idbeta commented on pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
idbeta commented on pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#issuecomment-730113107


   relate https://github.com/apache/apisix-dashboard/issues/607


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



[GitHub] [apisix-dashboard] juzhiyuan commented on pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#issuecomment-724563723


   The CD failure is not related to this PR, according to @nic-chen's approval, I will merge this PR soon.


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



[GitHub] [apisix-dashboard] idbeta commented on a change in pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
idbeta commented on a change in pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#discussion_r520310943



##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,245 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//CASE 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+		{
+			caseDesc:     "verify route without auth",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusUnauthorized,
+			Sleep:        sleepTime, 
+		},

Review comment:
       I delete the created data uniformly in the last function `TestConsumer_teardown`




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



[GitHub] [apisix-dashboard] idbeta commented on a change in pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
idbeta commented on a change in pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#discussion_r520318575



##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,245 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//CASE 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+		{
+			caseDesc:     "verify route without auth",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusUnauthorized,
+			Sleep:        sleepTime, 
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//CASE 2: add consumer without username
+func TestConsumer_add_consumer_without_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"plugins": {
+					"key-auth": {
+						"key": "auth-new"
+					}
+				},
+			  "desc": "test description"

Review comment:
       fixed

##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,245 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//CASE 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+		{
+			caseDesc:     "verify route without auth",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusUnauthorized,
+			Sleep:        sleepTime, 
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//CASE 2: add consumer without username
+func TestConsumer_add_consumer_without_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"plugins": {
+					"key-auth": {
+						"key": "auth-new"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusBadRequest,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-new"},
+			ExpectStatus: http.StatusUnauthorized,
+			Sleep:        sleepTime,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//CASE 3: add consumer with labels
+func TestConsumer_add_consumer_with_labels(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack2",
+				"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 consumer",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/apisix/admin/consumers/jack2",
+			Headers:      map[string]string{"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"},
+			ExpectStatus: http.StatusOK,
+			PartialBody:   "\"env\":\"production\"",
+			Sleep:        sleepTime, 
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-two"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//CASE 4: delete consumer
+func TestConsumer_delete_consumer(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc:     "delete consumer",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodDelete,
+			Path:         "/apisix/admin/consumers/jack",
+			Headers:      map[string]string{"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusUnauthorized,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+

Review comment:
       fixed

##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,245 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//CASE 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"

Review comment:
       fixed




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



[GitHub] [apisix-dashboard] juzhiyuan commented on pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
juzhiyuan commented on pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#issuecomment-730140914


   This PR would be reverted to https://github.com/apache/apisix-dashboard/pull/829 , one PR should be merged only when there have 2 approval at least.


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



[GitHub] [apisix-dashboard] membphis commented on a change in pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
membphis commented on a change in pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#discussion_r519745687



##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,245 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//CASE 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"

Review comment:
       bad indentation

##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,245 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//CASE 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+		{
+			caseDesc:     "verify route without auth",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusUnauthorized,
+			Sleep:        sleepTime, 
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//CASE 2: add consumer without username
+func TestConsumer_add_consumer_without_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"plugins": {
+					"key-auth": {
+						"key": "auth-new"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusBadRequest,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-new"},
+			ExpectStatus: http.StatusUnauthorized,
+			Sleep:        sleepTime,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//CASE 3: add consumer with labels
+func TestConsumer_add_consumer_with_labels(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack2",
+				"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 consumer",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/apisix/admin/consumers/jack2",
+			Headers:      map[string]string{"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"},
+			ExpectStatus: http.StatusOK,
+			PartialBody:   "\"env\":\"production\"",
+			Sleep:        sleepTime, 
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-two"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//CASE 4: delete consumer
+func TestConsumer_delete_consumer(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc:     "delete consumer",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodDelete,
+			Path:         "/apisix/admin/consumers/jack",
+			Headers:      map[string]string{"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusUnauthorized,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+

Review comment:
       remove those blank line

##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,245 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//CASE 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+		{
+			caseDesc:     "verify route without auth",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusUnauthorized,
+			Sleep:        sleepTime, 
+		},

Review comment:
       we need to delete the consumer `jack` at the end of the test case

##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,245 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//CASE 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+		{
+			caseDesc:     "verify route without auth",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusUnauthorized,
+			Sleep:        sleepTime, 
+		},

Review comment:
       it may cause wrong for other test cases

##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,245 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//CASE 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+		{
+			caseDesc:     "verify route without auth",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusUnauthorized,
+			Sleep:        sleepTime, 
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//CASE 2: add consumer without username
+func TestConsumer_add_consumer_without_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"plugins": {
+					"key-auth": {
+						"key": "auth-new"
+					}
+				},
+			  "desc": "test description"

Review comment:
       bad indentation too




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



[GitHub] [apisix-dashboard] idbeta commented on pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
idbeta commented on pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#issuecomment-723888583


   ping @nic-chen @membphis 


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



[GitHub] [apisix-dashboard] idbeta commented on a change in pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
idbeta commented on a change in pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#discussion_r519704521



##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,274 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//TEST 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 2: add consumer without username
+func TestConsumer_add_consumer_without_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusBadRequest,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 3: add consumer with labels
+func TestConsumer_add_consumer_with_labels(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create 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-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},  
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify consumer",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/apisix/admin/consumers/jack",
+			Headers:      map[string]string{"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"},
+			ExpectStatus: http.StatusOK,
+			PartialBody:   "\"env\":\"production\"",
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}
+

Review comment:
       My purpose  is to prevent the two use cases from coupling.

##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,274 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//TEST 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 2: add consumer without username
+func TestConsumer_add_consumer_without_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusBadRequest,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 3: add consumer with labels
+func TestConsumer_add_consumer_with_labels(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create 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-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},  
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify consumer",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/apisix/admin/consumers/jack",
+			Headers:      map[string]string{"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"},
+			ExpectStatus: http.StatusOK,
+			PartialBody:   "\"env\":\"production\"",
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 4: delete consumer
+func TestConsumer_delete_consumer(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",

Review comment:
       My purpose  is to prevent the two use cases from coupling.




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



[GitHub] [apisix-dashboard] juzhiyuan merged pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
juzhiyuan merged pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735


   


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



[GitHub] [apisix-dashboard] LiteSun commented on pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
LiteSun commented on pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#issuecomment-724504816


   There's a conflict here. Please fix it. @idbeta 


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



[GitHub] [apisix-dashboard] moonming commented on a change in pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
moonming commented on a change in pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#discussion_r519673317



##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,274 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//TEST 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}

Review comment:
       Need add test cases for non-auth header

##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,274 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//TEST 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 2: add consumer without username
+func TestConsumer_add_consumer_without_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusBadRequest,
+		},
+	}
+

Review comment:
       Not test data plane 

##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,274 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//TEST 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 2: add consumer without username
+func TestConsumer_add_consumer_without_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusBadRequest,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 3: add consumer with labels
+func TestConsumer_add_consumer_with_labels(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create 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-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},  
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify consumer",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/apisix/admin/consumers/jack",
+			Headers:      map[string]string{"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"},
+			ExpectStatus: http.StatusOK,
+			PartialBody:   "\"env\":\"production\"",
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}
+

Review comment:
       Ditto 

##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,274 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//TEST 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 2: add consumer without username
+func TestConsumer_add_consumer_without_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusBadRequest,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 3: add consumer with labels
+func TestConsumer_add_consumer_with_labels(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create 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-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},  
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify consumer",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/apisix/admin/consumers/jack",
+			Headers:      map[string]string{"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"},
+			ExpectStatus: http.StatusOK,
+			PartialBody:   "\"env\":\"production\"",
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 4: delete consumer
+func TestConsumer_delete_consumer(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",

Review comment:
       Why create again?

##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,274 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//TEST 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 2: add consumer without username
+func TestConsumer_add_consumer_without_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusBadRequest,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 3: add consumer with labels
+func TestConsumer_add_consumer_with_labels(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create 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-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},  
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify consumer",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/apisix/admin/consumers/jack",
+			Headers:      map[string]string{"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"},
+			ExpectStatus: http.StatusOK,
+			PartialBody:   "\"env\":\"production\"",
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 4: delete consumer
+func TestConsumer_delete_consumer(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",

Review comment:
       Ditto 




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



[GitHub] [apisix-dashboard] nic-chen commented on pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
nic-chen commented on pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#issuecomment-730152337


   > @nic-chen @membphis please take a look. Can we use admin API in e2e test?
   
   no, we can't. my fault, I shouldn't approve 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:
users@infra.apache.org



[GitHub] [apisix-dashboard] idbeta commented on a change in pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
idbeta commented on a change in pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#discussion_r519700854



##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,274 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//TEST 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 2: add consumer without username
+func TestConsumer_add_consumer_without_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusBadRequest,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 3: add consumer with labels
+func TestConsumer_add_consumer_with_labels(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create 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-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},  
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify consumer",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/apisix/admin/consumers/jack",
+			Headers:      map[string]string{"X-API-KEY": "edd1c9f034335f136f87ad84b625c8f1"},
+			ExpectStatus: http.StatusOK,
+			PartialBody:   "\"env\":\"production\"",
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+}
+
+//TEST 4: delete consumer
+func TestConsumer_delete_consumer(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",

Review comment:
       Does not need to be created again here.




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



[GitHub] [apisix-dashboard] juzhiyuan edited a comment on pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
juzhiyuan edited a comment on pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#issuecomment-730140914


   This PR would be reverted to https://github.com/apache/apisix-dashboard/pull/829 , one PR should be merged only when there has 2 approval at least.


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



[GitHub] [apisix-dashboard] moonming commented on pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
moonming commented on pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#issuecomment-730133418


   @nic-chen @membphis please take a look. Can we use admin API in e2e test?


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



[GitHub] [apisix-dashboard] idbeta commented on a change in pull request #735: test: add consumer e2e test

Posted by GitBox <gi...@apache.org>.
idbeta commented on a change in pull request #735:
URL: https://github.com/apache/apisix-dashboard/pull/735#discussion_r519702257



##########
File path: api/test/e2e/consumer_test.go
##########
@@ -0,0 +1,274 @@
+/*
+ * 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 (
+	 "net/http"
+	 "testing"
+ )
+
+//TEST 1: add consumer with username
+ func TestConsumer_add_consumer_with_username(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc: "create consumer",
+			Object:   MangerApiExpect(t),
+			Path:     "/apisix/admin/consumers",
+			Method:   http.MethodPut,
+			Body: `{
+				"username": "jack",
+				"plugins": {
+					"key-auth": {
+						"key": "auth-one"
+					}
+				},
+			  "desc": "test description"
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"key-auth": {}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": {
+						"172.16.238.20:1980": 1
+					}
+				}
+			  }`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "verify route",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			Headers:      map[string]string{"apikey": "auth-one"},
+			ExpectStatus: http.StatusOK,
+			Sleep:        sleepTime, //sleep x millisecond before verify route
+		},
+	}

Review comment:
       I added non-auth header test in the new submit
   ```
   {
     caseDesc:     "verify route without auth",
     Object:       APISIXExpect(t),
     Method:       http.MethodGet,
     Path:         "/hello",
     ExpectStatus: http.StatusUnauthorized,
     Sleep:        sleepTime, 
   }
   ```




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