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/27 08:14:50 UTC

[GitHub] [apisix-dashboard] membphis commented on a change in pull request #892: test: add e2e test cases for route with log plugin

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



##########
File path: api/test/e2e/route_with_log_plugin_test.go
##########
@@ -0,0 +1,191 @@
+/*
+ * 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 (
+	"io/ioutil"
+	"net/http"
+	"testing"
+	"time"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestRoute_With_Log_Plugin(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc:     "make sure the route is not created ",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusNotFound,
+			ExpectBody:   `{"error_msg":"404 Route Not Found"}`,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/opentracing",

Review comment:
       why not use /hello ?

##########
File path: api/test/docker/apisix_config.yaml
##########
@@ -38,3 +38,6 @@ apisix:
       enable: true
       ssl_cert: "/usr/local/apisix/certs/apisix.crt"
       ssl_cert_key: "/usr/local/apisix/certs/apisix.key"
+
+nginx_config:

Review comment:
        I don't think we need to change this

##########
File path: api/test/e2e/route_with_log_plugin_test.go
##########
@@ -0,0 +1,191 @@
+/*
+ * 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 (
+	"io/ioutil"
+	"net/http"
+	"testing"
+	"time"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestRoute_With_Log_Plugin(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc:     "make sure the route is not created ",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusNotFound,
+			ExpectBody:   `{"error_msg":"404 Route Not Found"}`,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/opentracing",
+				"plugins": {
+					"http-logger": {
+						"uri": "http://172.16.238.20:1982/hello",
+						"batch_max_size": 1,
+						"max_retry_count": 1,
+						"retry_delay": 2,
+						"buffer_duration": 2,
+						"inactive_timeout": 2,
+						"name": "http logger",
+						"timeout": 3,
+						"concat_method": "json"
+					}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": [{
+						"host": "172.16.238.20",
+						"port": 1981,
+						"weight": 1
+					}]
+				}
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "access route to trigger log",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/opentracing",
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "opentracing",
+			Sleep:        sleepTime,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+
+	// sleep for process log
+	time.Sleep(1500 * time.Millisecond)
+
+	// verify http logger by checking log
+	bytes, err := ioutil.ReadFile("../docker/apisix_logs/error.log")

Review comment:
        That is a not good idea. We should use a fake upstream for confirming if we got the log data.

##########
File path: api/test/e2e/route_with_log_plugin_test.go
##########
@@ -0,0 +1,191 @@
+/*
+ * 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 (
+	"io/ioutil"
+	"net/http"
+	"testing"
+	"time"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestRoute_With_Log_Plugin(t *testing.T) {
+	tests := []HttpTestCase{
+		{
+			caseDesc:     "make sure the route is not created ",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusNotFound,
+			ExpectBody:   `{"error_msg":"404 Route Not Found"}`,
+		},
+		{
+			caseDesc: "create route",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r1",
+			Body: `{
+				"uri": "/opentracing",
+				"plugins": {
+					"http-logger": {
+						"uri": "http://172.16.238.20:1982/hello",
+						"batch_max_size": 1,
+						"max_retry_count": 1,
+						"retry_delay": 2,
+						"buffer_duration": 2,
+						"inactive_timeout": 2,
+						"name": "http logger",
+						"timeout": 3,
+						"concat_method": "json"
+					}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": [{
+						"host": "172.16.238.20",
+						"port": 1981,
+						"weight": 1
+					}]
+				}
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "access route to trigger log",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/opentracing",
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "opentracing",
+			Sleep:        sleepTime,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+
+	// sleep for process log
+	time.Sleep(1500 * time.Millisecond)
+
+	// verify http logger by checking log
+	bytes, err := ioutil.ReadFile("../docker/apisix_logs/error.log")
+	assert.Nil(t, err)
+	logContent := string(bytes)
+	assert.Contains(t, logContent, "Batch Processor[http logger] successfully processed the entries")
+
+	tests = []HttpTestCase{
+		{
+			caseDesc: "create route with wrong https endpoint",
+			Object:   MangerApiExpect(t),
+			Method:   http.MethodPut,
+			Path:     "/apisix/admin/routes/r2",
+			Body: `{
+				"uri": "/hello",
+				"plugins": {
+					"http-logger": {
+						"uri": "https://127.0.0.1:8888/hello-world-http",
+						"batch_max_size": 1,
+						"max_retry_count": 1,
+						"retry_delay": 2,
+						"buffer_duration": 2,
+						"inactive_timeout": 2,
+						"name": "http logger",
+						"timeout": 3,
+						"concat_method": "json"
+					}
+				},
+				"upstream": {
+					"type": "roundrobin",
+					"nodes": [{
+						"host": "172.16.238.20",
+						"port": 1982,
+						"weight": 1
+					}]
+				}
+			}`,
+			Headers:      map[string]string{"Authorization": token},
+			ExpectStatus: http.StatusOK,
+		},
+		{
+			caseDesc:     "access route to trigger log",
+			Object:       APISIXExpect(t),
+			Method:       http.MethodGet,
+			Path:         "/hello",
+			ExpectStatus: http.StatusOK,
+			ExpectBody:   "hello world",
+			Sleep:        sleepTime,
+		},
+	}
+
+	for _, tc := range tests {
+		testCaseCheck(tc)
+	}
+
+	// sleep for process log
+	time.Sleep(1500 * time.Millisecond)
+
+	// verify http logger by checking log
+	bytes, err = ioutil.ReadFile("../docker/apisix_logs/error.log")

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