diff --git a/.github/workflows/backend-e2e-test.yml b/.github/workflows/backend-e2e-test.yml index 8c70c69a1b..7ba1cbddfc 100644 --- a/.github/workflows/backend-e2e-test.yml +++ b/.github/workflows/backend-e2e-test.yml @@ -30,3 +30,25 @@ jobs: - name: run test working-directory: ./api/test/e2e run: go test -v + + - name: re-generate json schema + working-directory: ./api/ + run: | + curl 127.0.0.1:9090/v1/schema > ./conf/schema.json + + - name: stop docker compose + working-directory: ./api/test/docker + run: | + docker-compose down + sleep 10 + + - name: re-run docker compose + working-directory: ./api/test/docker + run: | + docker-compose up -d --build + sleep 5 + docker logs docker_managerapi_1 + + - name: run test for plugin skywalking + working-directory: ./api/test/e2e/skywalking + run: go test -v diff --git a/api/conf/schema.json b/api/conf/schema.json index cf0a89152c..9ee960357e 100644 --- a/api/conf/schema.json +++ b/api/conf/schema.json @@ -182,12 +182,12 @@ "type": "string" }, "host": { - "pattern": "^\\*?[0-9a-zA-Z-.]+$", + "pattern": "^\\*?[0-9a-zA-Z-._]+$", "type": "string" }, "hosts": { "items": { - "pattern": "^\\*?[0-9a-zA-Z-.]+$", + "pattern": "^\\*?[0-9a-zA-Z-._]+$", "type": "string" }, "minItems": 1, @@ -292,6 +292,17 @@ "minLength": 10, "type": "string" }, + "script_id": { + "anyOf": [{ + "maxLength": 64, + "minLength": 1, + "pattern": "^[a-zA-Z0-9-_.]+$", + "type": "string" + }, { + "minimum": 1, + "type": "integer" + }] + }, "service_id": { "anyOf": [{ "maxLength": 64, @@ -319,8 +330,6 @@ "additionalProperties": false, "anyOf": [{ "required": ["nodes", "type"] - }, { - "required": ["k8s_deployment_info", "type"] }, { "required": ["service_name", "type"] }], @@ -367,7 +376,7 @@ "type": "object" }, "host": { - "pattern": "^\\*?[0-9a-zA-Z-.]+$", + "pattern": "^\\*?[0-9a-zA-Z-._]+$", "type": "string" }, "http_path": { @@ -542,38 +551,6 @@ "type": "integer" }] }, - "k8s_deployment_info": { - "anyOf": [{ - "required": ["deploy_name", "namespace", "port"] - }, { - "required": ["namespace", "port", "service_name"] - }], - "properties": { - "backend_type": { - "default": "pod", - "description": "k8s service name", - "enum": ["pod", "svc"], - "type": "string" - }, - "deploy_name": { - "description": "k8s deployment name", - "type": "string" - }, - "namespace": { - "description": "k8s namespace", - "type": "string" - }, - "port": { - "minimum": 0, - "type": "number" - }, - "service_name": { - "description": "k8s service name", - "type": "string" - } - }, - "type": "object" - }, "key": { "description": "the key of chash for dynamic load balancing", "type": "string" @@ -612,7 +589,7 @@ "items": { "properties": { "host": { - "pattern": "^\\*?[0-9a-zA-Z-.]+$", + "pattern": "^\\*?[0-9a-zA-Z-._]+$", "type": "string" }, "metadata": { @@ -678,7 +655,7 @@ "type": "integer" }, "upstream_host": { - "pattern": "^\\*?[0-9a-zA-Z-.]+$", + "pattern": "^\\*?[0-9a-zA-Z-._]+$", "type": "string" } }, @@ -712,15 +689,8 @@ "vars": { "items": { "description": "Nginx builtin variable name and value", - "items": { - "anyOf": [{ - "type": "string" - }, { - "type": "number" - }], - "maxItems": 3, - "minItems": 2 - }, + "maxItems": 4, + "minItems": 2, "type": "array" }, "type": "array" @@ -787,8 +757,6 @@ "additionalProperties": false, "anyOf": [{ "required": ["nodes", "type"] - }, { - "required": ["k8s_deployment_info", "type"] }, { "required": ["service_name", "type"] }], @@ -835,7 +803,7 @@ "type": "object" }, "host": { - "pattern": "^\\*?[0-9a-zA-Z-.]+$", + "pattern": "^\\*?[0-9a-zA-Z-._]+$", "type": "string" }, "http_path": { @@ -1010,38 +978,6 @@ "type": "integer" }] }, - "k8s_deployment_info": { - "anyOf": [{ - "required": ["deploy_name", "namespace", "port"] - }, { - "required": ["namespace", "port", "service_name"] - }], - "properties": { - "backend_type": { - "default": "pod", - "description": "k8s service name", - "enum": ["pod", "svc"], - "type": "string" - }, - "deploy_name": { - "description": "k8s deployment name", - "type": "string" - }, - "namespace": { - "description": "k8s namespace", - "type": "string" - }, - "port": { - "minimum": 0, - "type": "number" - }, - "service_name": { - "description": "k8s service name", - "type": "string" - } - }, - "type": "object" - }, "key": { "description": "the key of chash for dynamic load balancing", "type": "string" @@ -1080,7 +1016,7 @@ "items": { "properties": { "host": { - "pattern": "^\\*?[0-9a-zA-Z-.]+$", + "pattern": "^\\*?[0-9a-zA-Z-._]+$", "type": "string" }, "metadata": { @@ -1146,7 +1082,7 @@ "type": "integer" }, "upstream_host": { - "pattern": "^\\*?[0-9a-zA-Z-.]+$", + "pattern": "^\\*?[0-9a-zA-Z-._]+$", "type": "string" } }, @@ -1241,6 +1177,7 @@ "pattern": "^\\*?[0-9a-zA-Z-.]+$", "type": "string" }, + "minItems": 1, "type": "array" }, "status": { @@ -1327,8 +1264,6 @@ "additionalProperties": false, "anyOf": [{ "required": ["nodes", "type"] - }, { - "required": ["k8s_deployment_info", "type"] }, { "required": ["service_name", "type"] }], @@ -1375,7 +1310,7 @@ "type": "object" }, "host": { - "pattern": "^\\*?[0-9a-zA-Z-.]+$", + "pattern": "^\\*?[0-9a-zA-Z-._]+$", "type": "string" }, "http_path": { @@ -1550,38 +1485,6 @@ "type": "integer" }] }, - "k8s_deployment_info": { - "anyOf": [{ - "required": ["deploy_name", "namespace", "port"] - }, { - "required": ["namespace", "port", "service_name"] - }], - "properties": { - "backend_type": { - "default": "pod", - "description": "k8s service name", - "enum": ["pod", "svc"], - "type": "string" - }, - "deploy_name": { - "description": "k8s deployment name", - "type": "string" - }, - "namespace": { - "description": "k8s namespace", - "type": "string" - }, - "port": { - "minimum": 0, - "type": "number" - }, - "service_name": { - "description": "k8s service name", - "type": "string" - } - }, - "type": "object" - }, "key": { "description": "the key of chash for dynamic load balancing", "type": "string" @@ -1620,7 +1523,7 @@ "items": { "properties": { "host": { - "pattern": "^\\*?[0-9a-zA-Z-.]+$", + "pattern": "^\\*?[0-9a-zA-Z-._]+$", "type": "string" }, "metadata": { @@ -1686,7 +1589,7 @@ "type": "integer" }, "upstream_host": { - "pattern": "^\\*?[0-9a-zA-Z-.]+$", + "pattern": "^\\*?[0-9a-zA-Z-._]+$", "type": "string" } }, @@ -1710,8 +1613,6 @@ "additionalProperties": false, "anyOf": [{ "required": ["nodes", "type"] - }, { - "required": ["k8s_deployment_info", "type"] }, { "required": ["service_name", "type"] }], @@ -1758,7 +1659,7 @@ "type": "object" }, "host": { - "pattern": "^\\*?[0-9a-zA-Z-.]+$", + "pattern": "^\\*?[0-9a-zA-Z-._]+$", "type": "string" }, "http_path": { @@ -1933,38 +1834,6 @@ "type": "integer" }] }, - "k8s_deployment_info": { - "anyOf": [{ - "required": ["deploy_name", "namespace", "port"] - }, { - "required": ["namespace", "port", "service_name"] - }], - "properties": { - "backend_type": { - "default": "pod", - "description": "k8s service name", - "enum": ["pod", "svc"], - "type": "string" - }, - "deploy_name": { - "description": "k8s deployment name", - "type": "string" - }, - "namespace": { - "description": "k8s namespace", - "type": "string" - }, - "port": { - "minimum": 0, - "type": "number" - }, - "service_name": { - "description": "k8s service name", - "type": "string" - } - }, - "type": "object" - }, "key": { "description": "the key of chash for dynamic load balancing", "type": "string" @@ -2003,7 +1872,7 @@ "items": { "properties": { "host": { - "pattern": "^\\*?[0-9a-zA-Z-.]+$", + "pattern": "^\\*?[0-9a-zA-Z-._]+$", "type": "string" }, "metadata": { @@ -2069,20 +1938,20 @@ "type": "integer" }, "upstream_host": { - "pattern": "^\\*?[0-9a-zA-Z-.]+$", + "pattern": "^\\*?[0-9a-zA-Z-._]+$", "type": "string" } }, "type": "object" }, - "upstream_hash_header_schema": { - "pattern": "^[a-zA-Z0-9-_]+$", - "type": "string" - }, - "upstream_hash_vars_schema": { - "pattern": "^((uri|server_name|server_addr|request_uri|remote_port|remote_addr|query_string|host|hostname)|arg_[0-9a-zA-z_-]+)$", - "type": "string" - } + "upstream_hash_header_schema": { + "pattern": "^[a-zA-Z0-9-_]+$", + "type": "string" + }, + "upstream_hash_vars_schema": { + "pattern": "^((uri|server_name|server_addr|request_uri|remote_port|remote_addr|query_string|host|hostname)|arg_[0-9a-zA-z_-]+)$", + "type": "string" + } }, "plugins": { "api-breaker": { @@ -2408,75 +2277,6 @@ }, "version": 0.1 }, - "error-log-logger": { - "metadata_schema": { - "properties": { - "batch_max_size": { - "default": 1000, - "minimum": 0, - "type": "integer" - }, - "buffer_duration": { - "default": 60, - "minimum": 1, - "type": "integer" - }, - "host": { - "pattern": "^\\*?[0-9a-zA-Z-.]+$", - "type": "string" - }, - "inactive_timeout": { - "default": 3, - "minimum": 1, - "type": "integer" - }, - "keepalive": { - "default": 30, - "minimum": 1, - "type": "integer" - }, - "level": { - "default": "WARN", - "enum": ["ALERT", "CRIT", "DEBUG", "EMERG", "ERR", "ERROR", "INFO", "NOTICE", "STDERR", "WARN"], - "type": "string" - }, - "max_retry_count": { - "default": 0, - "minimum": 0, - "type": "integer" - }, - "name": { - "default": "error-log-logger", - "type": "string" - }, - "port": { - "minimum": 0, - "type": "integer" - }, - "retry_delay": { - "default": 1, - "minimum": 0, - "type": "integer" - }, - "timeout": { - "default": 3, - "minimum": 1, - "type": "integer" - }, - "tls": { - "default": false, - "type": "boolean" - }, - "tls_server_name": { - "type": "string" - } - }, - "required": ["host", "port"], - "type": "object" - }, - "priority": 1091, - "version": 0.1 - }, "fault-injection": { "priority": 11000, "schema": { @@ -3090,19 +2890,6 @@ }, "version": 0.1 }, - "log-rotate": { - "priority": 100, - "schema": { - "additionalProperties": false, - "properties": { - "disable": { - "type": "boolean" - } - }, - "type": "object" - }, - "version": 0.1 - }, "mqtt-proxy": { "priority": 1000, "schema": { @@ -3130,19 +2917,6 @@ }, "version": 0.1 }, - "node-status": { - "priority": 1000, - "schema": { - "additionalProperties": false, - "properties": { - "disable": { - "type": "boolean" - } - }, - "type": "object" - }, - "version": 0.1 - }, "openid-connect": { "priority": 2599, "schema": { @@ -3382,7 +3156,7 @@ }, "whitelist": { "items": { - "pattern": "^\\*?[0-9a-zA-Z-.]+$", + "pattern": "^\\*?[0-9a-zA-Z-._]+$", "type": "string" }, "minItems": 1, @@ -3472,19 +3246,6 @@ }, "version": 0.1 }, - "server-info": { - "priority": 990, - "schema": { - "additionalProperties": false, - "properties": { - "disable": { - "type": "boolean" - } - }, - "type": "object" - }, - "version": 0.1 - }, "serverless-post-function": { "priority": -2000, "schema": { @@ -3529,42 +3290,6 @@ }, "version": 0.1 }, - "skywalking": { - "metadata_schema": { - "additionalProperties": false, - "properties": { - "endpoint_addr": { - "default": "http://127.0.0.1:12800", - "type": "string" - }, - "service_instance_name": { - "default": "APISIX Instance Name", - "description": "User Service Instance Name", - "type": "string" - }, - "service_name": { - "default": "APISIX", - "description": "service name for skywalking", - "type": "string" - } - }, - "type": "object" - }, - "priority": -1100, - "schema": { - "additionalProperties": false, - "properties": { - "sample_ratio": { - "default": 1, - "maximum": 1, - "minimum": 0.00001, - "type": "number" - } - }, - "type": "object" - }, - "version": 0.1 - }, "sls-logger": { "priority": 406, "schema": { @@ -3765,6 +3490,441 @@ }, "version": 0.1 }, + "traffic-split": { + "priority": 966, + "schema": { + "properties": { + "rules": { + "items": { + "properties": { + "match": { + "default": [{ + "vars": [ + [0, ">", "server_port"] + ] + }], + "items": { + "properties": { + "vars": { + "items": { + "additionalItems": { + "anyOf": [{ + "type": "string" + }, { + "type": "number" + }, { + "type": "boolean" + }, { + "items": { + "anyOf": [{ + "maxLength": 100, + "minLength": 1, + "type": "string" + }, { + "type": "number" + }, { + "type": "boolean" + }] + }, + "type": "array", + "uniqueItems": true + }] + }, + "items": [{ + "maxLength": 100, + "minLength": 1, + "type": "string" + }, { + "maxLength": 2, + "minLength": 1, + "type": "string" + }], + "maxItems": 10, + "minItems": 0, + "type": "array" + }, + "type": "array" + } + }, + "type": "object" + }, + "type": "array" + }, + "weighted_upstreams": { + "default": [{ + "weight": 1 + }], + "items": { + "properties": { + "upstream": { + "additionalProperties": false, + "anyOf": [{ + "required": ["nodes", "type"] + }, { + "required": ["service_name", "type"] + }], + "properties": { + "checks": { + "additionalProperties": false, + "anyOf": [{ + "required": ["active"] + }, { + "required": ["active", "passive"] + }], + "properties": { + "active": { + "properties": { + "concurrency": { + "default": 10, + "type": "integer" + }, + "healthy": { + "properties": { + "http_statuses": { + "default": [200, 302], + "items": { + "maximum": 599, + "minimum": 200, + "type": "integer" + }, + "minItems": 1, + "type": "array", + "uniqueItems": true + }, + "interval": { + "default": 0, + "minimum": 1, + "type": "integer" + }, + "successes": { + "default": 2, + "maximum": 254, + "minimum": 1, + "type": "integer" + } + }, + "type": "object" + }, + "host": { + "pattern": "^\\*?[0-9a-zA-Z-._]+$", + "type": "string" + }, + "http_path": { + "default": "/", + "type": "string" + }, + "https_verify_certificate": { + "default": true, + "type": "boolean" + }, + "port": { + "maximum": 65535, + "minimum": 1, + "type": "integer" + }, + "req_headers": { + "items": { + "type": "string", + "uniqueItems": true + }, + "minItems": 1, + "type": "array" + }, + "timeout": { + "default": 1, + "type": "number" + }, + "type": { + "default": "http", + "enum": ["http", "https", "tcp"], + "type": "string" + }, + "unhealthy": { + "properties": { + "http_failures": { + "default": 5, + "maximum": 254, + "minimum": 1, + "type": "integer" + }, + "http_statuses": { + "default": [404, 429, 500, 501, 502, 503, 504, 505], + "items": { + "maximum": 599, + "minimum": 200, + "type": "integer" + }, + "minItems": 1, + "type": "array", + "uniqueItems": true + }, + "interval": { + "default": 0, + "minimum": 1, + "type": "integer" + }, + "tcp_failures": { + "default": 2, + "maximum": 254, + "minimum": 1, + "type": "integer" + }, + "timeouts": { + "default": 3, + "maximum": 254, + "minimum": 1, + "type": "integer" + } + }, + "type": "object" + } + }, + "type": "object" + }, + "passive": { + "properties": { + "healthy": { + "properties": { + "http_statuses": { + "default": [200, 201, 202, 203, 204, 205, 206, 207, 208, 226, 300, 301, 302, 303, 304, 305, 306, 307, 308], + "items": { + "maximum": 599, + "minimum": 200, + "type": "integer" + }, + "minItems": 1, + "type": "array", + "uniqueItems": true + }, + "successes": { + "default": 5, + "maximum": 254, + "minimum": 1, + "type": "integer" + } + }, + "type": "object" + }, + "type": { + "default": "http", + "enum": ["http", "https", "tcp"], + "type": "string" + }, + "unhealthy": { + "properties": { + "http_failures": { + "default": 5, + "maximum": 254, + "minimum": 1, + "type": "integer" + }, + "http_statuses": { + "default": [429, 500, 503], + "items": { + "maximum": 599, + "minimum": 200, + "type": "integer" + }, + "minItems": 1, + "type": "array", + "uniqueItems": true + }, + "tcp_failures": { + "default": 2, + "maximum": 254, + "minimum": 1, + "type": "integer" + }, + "timeouts": { + "default": 7, + "maximum": 254, + "minimum": 1, + "type": "integer" + } + }, + "type": "object" + } + }, + "type": "object" + } + }, + "type": "object" + }, + "create_time": { + "type": "integer" + }, + "desc": { + "maxLength": 256, + "type": "string" + }, + "discovery_type": { + "description": "discovery type", + "type": "string" + }, + "enable_websocket": { + "description": "enable websocket for request", + "type": "boolean" + }, + "hash_on": { + "default": "vars", + "enum": ["consumer", "cookie", "header", "vars"], + "type": "string" + }, + "id": { + "anyOf": [{ + "maxLength": 64, + "minLength": 1, + "pattern": "^[a-zA-Z0-9-_.]+$", + "type": "string" + }, { + "minimum": 1, + "type": "integer" + }] + }, + "key": { + "description": "the key of chash for dynamic load balancing", + "type": "string" + }, + "labels": { + "description": "key/value pairs to specify attributes", + "maxProperties": 16, + "patternProperties": { + ".*": { + "description": "value of label", + "maxLength": 64, + "minLength": 1, + "pattern": "^[a-zA-Z0-9-_.]+$", + "type": "string" + } + }, + "type": "object" + }, + "name": { + "maxLength": 100, + "minLength": 1, + "type": "string" + }, + "nodes": { + "anyOf": [{ + "minProperties": 1, + "patternProperties": { + ".*": { + "description": "weight of node", + "minimum": 0, + "type": "integer" + } + }, + "type": "object" + }, { + "items": { + "properties": { + "host": { + "pattern": "^\\*?[0-9a-zA-Z-._]+$", + "type": "string" + }, + "metadata": { + "description": "metadata of node", + "type": "object" + }, + "port": { + "description": "port of node", + "minimum": 1, + "type": "integer" + }, + "weight": { + "description": "weight of node", + "minimum": 0, + "type": "integer" + } + }, + "required": ["host", "port", "weight"], + "type": "object" + }, + "type": "array" + }] + }, + "pass_host": { + "default": "pass", + "description": "mod of host passing", + "enum": ["node", "pass", "rewrite"], + "type": "string" + }, + "retries": { + "minimum": 0, + "type": "integer" + }, + "service_name": { + "maxLength": 100, + "minLength": 1, + "type": "string" + }, + "timeout": { + "properties": { + "connect": { + "minimum": 0, + "type": "number" + }, + "read": { + "minimum": 0, + "type": "number" + }, + "send": { + "minimum": 0, + "type": "number" + } + }, + "required": ["connect", "read", "send"], + "type": "object" + }, + "type": { + "description": "algorithms of load balancing", + "enum": ["chash", "ewma", "roundrobin"], + "type": "string" + }, + "update_time": { + "type": "integer" + }, + "upstream_host": { + "pattern": "^\\*?[0-9a-zA-Z-._]+$", + "type": "string" + } + }, + "type": "object" + }, + "upstream_id": { + "anyOf": [{ + "maxLength": 64, + "minLength": 1, + "pattern": "^[a-zA-Z0-9-_.]+$", + "type": "string" + }, { + "minimum": 1, + "type": "integer" + }] + }, + "weight": { + "default": 1, + "description": "used to split traffic between differentupstreams for plugin configuration", + "minimum": 0, + "type": "integer" + } + }, + "type": "object" + }, + "maxItems": 20, + "minItems": 1, + "type": "array" + } + }, + "type": "object" + }, + "type": "array" + } + }, + "type": "object" + }, + "version": 0.1 + }, "udp-logger": { "priority": 400, "schema": { @@ -3885,4 +4045,4 @@ "version": 0.1 } } -} \ No newline at end of file +} diff --git a/api/test/docker/apisix_config.yaml b/api/test/docker/apisix_config.yaml index 47bdb4ea7b..e292839ffc 100644 --- a/api/test/docker/apisix_config.yaml +++ b/api/test/docker/apisix_config.yaml @@ -41,6 +41,11 @@ apisix: ssl_cert: "/usr/local/apisix/certs/apisix.crt" ssl_cert_key: "/usr/local/apisix/certs/apisix.key" + enable_control: true + control: + ip: "0.0.0.0" + port: 9090 + nginx_config: error_log_level: "debug" diff --git a/api/test/docker/docker-compose.yaml b/api/test/docker/docker-compose.yaml index cacca65749..cb2d67eac4 100644 --- a/api/test/docker/docker-compose.yaml +++ b/api/test/docker/docker-compose.yaml @@ -144,6 +144,7 @@ services: - node3 ports: - '9080:9080/tcp' + - '9090:9090/tcp' - '9443:9443/tcp' networks: apisix_dashboard_e2e: diff --git a/api/test/e2e/base.go b/api/test/e2e/base.go index 4bed9cb1d7..ea8c2fe8f3 100644 --- a/api/test/e2e/base.go +++ b/api/test/e2e/base.go @@ -20,10 +20,12 @@ import ( "bytes" "context" "crypto/tls" - + "fmt" "io/ioutil" "net" "net/http" + "os/exec" + "strings" "testing" "time" @@ -32,12 +34,15 @@ import ( "github.com/tidwall/gjson" ) -var token string +var ( + token string + Token string -var APISIXHost = "http://127.0.0.1:9080" -var APISIXInternalUrl = "http://172.16.238.30:9080" -var APISIXSingleWorkerHost = "http://127.0.0.1:9081" -var ManagerAPIHost = "http://127.0.0.1:9000" + APISIXHost = "http://127.0.0.1:9080" + APISIXInternalUrl = "http://172.16.238.30:9080" + APISIXSingleWorkerHost = "http://127.0.0.1:9081" + ManagerAPIHost = "http://127.0.0.1:9000" +) func init() { //login to get auth token @@ -67,6 +72,7 @@ func init() { respond := gjson.ParseBytes(body) token = respond.Get("data.token").String() + Token = token } func httpGet(url string) ([]byte, int, error) { @@ -239,3 +245,34 @@ func testCaseCheck(tc HttpTestCase, t *testing.T) { } }) } + +func RunTestCases(tc HttpTestCase, t *testing.T) { + testCaseCheck(tc, t) +} + +func ReadAPISIXErrorLog(t *testing.T) string { + cmd := exec.Command("pwd") + pwdByte, err := cmd.CombinedOutput() + pwd := string(pwdByte) + pwd = strings.Replace(pwd, "\n", "", 1) + pwd = pwd[:strings.Index(pwd, "/e2e")] + bytes, err := ioutil.ReadFile(pwd + "/docker/apisix_logs/error.log") + assert.Nil(t, err) + logContent := string(bytes) + + return logContent +} + +func CleanAPISIXErrorLog(t *testing.T) { + cmd := exec.Command("pwd") + pwdByte, err := cmd.CombinedOutput() + pwd := string(pwdByte) + pwd = strings.Replace(pwd, "\n", "", 1) + pwd = pwd[:strings.Index(pwd, "/e2e")] + cmd = exec.Command("sudo", "echo", " > ", pwd + "/docker/apisix_logs/error.log") + _, err = cmd.CombinedOutput() + if err != nil { + fmt.Println("cmd error:", err.Error()) + } + assert.Nil(t, err) +} diff --git a/api/test/e2e/route_with_log_plugin_test.go b/api/test/e2e/route_with_log_plugin_test.go index 2203d1b287..f32195f4aa 100644 --- a/api/test/e2e/route_with_log_plugin_test.go +++ b/api/test/e2e/route_with_log_plugin_test.go @@ -17,43 +17,16 @@ package e2e import ( - "fmt" - "io/ioutil" "net/http" - "os/exec" - "strings" "testing" "time" "github.com/stretchr/testify/assert" ) -func readAPISIXErrorLog(t *testing.T) string { - bytes, err := ioutil.ReadFile("../docker/apisix_logs/error.log") - assert.Nil(t, err) - logContent := string(bytes) - return logContent -} - -func cleanAPISIXErrorLog(t *testing.T) { - cmd := exec.Command("pwd") - pwdByte, err := cmd.CombinedOutput() - pwd := string(pwdByte) - - pwd = strings.Replace(pwd, "\n", "", 1) - pwd = strings.Replace(pwd, "/e2e", "", 1) - - cmd = exec.Command("sudo", "echo", " > ", pwd+"/docker/apisix_logs/error.log") - _, err = cmd.CombinedOutput() - if err != nil { - fmt.Println("cmd error:", err.Error()) - } - assert.Nil(t, err) -} - func TestRoute_With_Log_Plugin(t *testing.T) { // clean log - cleanAPISIXErrorLog(t) + CleanAPISIXErrorLog(t) tests := []HttpTestCase{ { @@ -116,11 +89,11 @@ func TestRoute_With_Log_Plugin(t *testing.T) { // verify http logger by checking log //todo: should use a fake upstream for confirming whether we got the log data. - logContent := readAPISIXErrorLog(t) + logContent := ReadAPISIXErrorLog(t) assert.Contains(t, logContent, "Batch Processor[http logger] successfully processed the entries") // clean log - cleanAPISIXErrorLog(t) + CleanAPISIXErrorLog(t) tests = []HttpTestCase{ { @@ -175,11 +148,11 @@ func TestRoute_With_Log_Plugin(t *testing.T) { // verify http logger by checking log //todo: should use a fake upstream for confirming whether we got the log data. - logContent = readAPISIXErrorLog(t) + logContent = ReadAPISIXErrorLog(t) assert.Contains(t, logContent, "Batch Processor[http logger] failed to process entries: failed to connect to host[127.0.0.1] port[8888] connection refused") // clean log - cleanAPISIXErrorLog(t) + CleanAPISIXErrorLog(t) // todo: check disable http logger diff --git a/api/test/e2e/route_with_trace_plugin_test.go b/api/test/e2e/skywalking/route_with_trace_plugin_test.go similarity index 79% rename from api/test/e2e/route_with_trace_plugin_test.go rename to api/test/e2e/skywalking/route_with_trace_plugin_test.go index fb9f6a6ee5..26d1959f04 100644 --- a/api/test/e2e/route_with_trace_plugin_test.go +++ b/api/test/e2e/skywalking/route_with_trace_plugin_test.go @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package e2e +package skywalking import ( "net/http" @@ -22,13 +22,17 @@ import ( "time" "github.com/stretchr/testify/assert" + + "e2e" ) +var sleepTime = time.Duration(300) * time.Millisecond + func TestRoute_With_Plugin_Skywalking(t *testing.T) { - tests := []HttpTestCase{ + tests := []e2e.HttpTestCase{ { Desc: "make sure the route is not created ", - Object: APISIXExpect(t), + Object: e2e.APISIXExpect(t), Method: http.MethodGet, Path: "/hello", ExpectStatus: http.StatusNotFound, @@ -36,7 +40,7 @@ func TestRoute_With_Plugin_Skywalking(t *testing.T) { }, { Desc: "create route", - Object: ManagerApiExpect(t), + Object: e2e.ManagerApiExpect(t), Method: http.MethodPut, Path: "/apisix/admin/routes/r1", Body: `{ @@ -55,12 +59,12 @@ func TestRoute_With_Plugin_Skywalking(t *testing.T) { }] } }`, - Headers: map[string]string{"Authorization": token}, + Headers: map[string]string{"Authorization": e2e.Token}, ExpectStatus: http.StatusOK, }, { Desc: "tiger skywalking", - Object: APISIXExpect(t), + Object: e2e.APISIXExpect(t), Method: http.MethodGet, Path: "/hello", ExpectStatus: http.StatusOK, @@ -70,23 +74,23 @@ func TestRoute_With_Plugin_Skywalking(t *testing.T) { } for _, tc := range tests { - testCaseCheck(tc, t) + e2e.RunTestCases(tc, t) } // sleep for process log time.Sleep(4 * time.Second) // verify by checking log - logContent := readAPISIXErrorLog(t) + logContent := e2e.ReadAPISIXErrorLog(t) assert.Contains(t, logContent, "segments reported") // clean log - cleanAPISIXErrorLog(t) + e2e.CleanAPISIXErrorLog(t) - tests = []HttpTestCase{ + tests = []e2e.HttpTestCase{ { Desc: "update route to change sample ratio", - Object: ManagerApiExpect(t), + Object: e2e.ManagerApiExpect(t), Method: http.MethodPut, Path: "/apisix/admin/routes/r1", Body: `{ @@ -105,12 +109,12 @@ func TestRoute_With_Plugin_Skywalking(t *testing.T) { }] } }`, - Headers: map[string]string{"Authorization": token}, + Headers: map[string]string{"Authorization": e2e.Token}, ExpectStatus: http.StatusOK, }, { Desc: "access the route", - Object: APISIXExpect(t), + Object: e2e.APISIXExpect(t), Method: http.MethodGet, Path: "/hello", ExpectStatus: http.StatusOK, @@ -120,31 +124,31 @@ func TestRoute_With_Plugin_Skywalking(t *testing.T) { } for _, tc := range tests { - testCaseCheck(tc, t) + e2e.RunTestCases(tc, t) } // sleep for process log time.Sleep(4 * time.Second) // verify by checking log - logContent = readAPISIXErrorLog(t) + logContent = e2e.ReadAPISIXErrorLog(t) assert.Contains(t, logContent, "miss sampling, ignore") // clean log - cleanAPISIXErrorLog(t) + e2e.CleanAPISIXErrorLog(t) - tests = []HttpTestCase{ + tests = []e2e.HttpTestCase{ { Desc: "delete route", - Object: ManagerApiExpect(t), + Object: e2e.ManagerApiExpect(t), Method: http.MethodDelete, Path: "/apisix/admin/routes/r1", - Headers: map[string]string{"Authorization": token}, + Headers: map[string]string{"Authorization": e2e.Token}, ExpectStatus: http.StatusOK, }, { Desc: "make sure the route has been deleted", - Object: APISIXExpect(t), + Object: e2e.APISIXExpect(t), Method: http.MethodGet, Path: "/hello_", ExpectStatus: http.StatusNotFound, @@ -154,6 +158,6 @@ func TestRoute_With_Plugin_Skywalking(t *testing.T) { } for _, tc := range tests { - testCaseCheck(tc, t) + e2e.RunTestCases(tc, t) } }