mirror of
https://github.com/alibaba/higress.git
synced 2026-04-22 04:27:26 +08:00
feat: add e2e test for envoy filter (#710)
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/alibaba/higress/pkg/ingress/kube/configmap"
|
||||
"github.com/alibaba/higress/test/e2e/conformance/utils/envoy"
|
||||
"github.com/alibaba/higress/test/e2e/conformance/utils/http"
|
||||
"github.com/alibaba/higress/test/e2e/conformance/utils/kubernetes"
|
||||
"github.com/alibaba/higress/test/e2e/conformance/utils/suite"
|
||||
@@ -25,6 +26,266 @@ import (
|
||||
|
||||
func init() {
|
||||
Register(ConfigmapGzip)
|
||||
Register(ConfigMapGzipEnvoy)
|
||||
}
|
||||
|
||||
var testCases = []struct {
|
||||
higressConfig *configmap.HigressConfig
|
||||
envoyAssertion envoy.Assertion
|
||||
httpAssert http.Assertion
|
||||
}{
|
||||
{
|
||||
higressConfig: &configmap.HigressConfig{
|
||||
Gzip: &configmap.Gzip{
|
||||
Enable: false,
|
||||
MinContentLength: 1024,
|
||||
ContentType: []string{"text/html", "text/css", "text/plain", "text/xml", "application/json", "application/javascript", "application/xhtml+xml", "image/svg+xml"},
|
||||
DisableOnEtagHeader: true,
|
||||
MemoryLevel: 5,
|
||||
WindowBits: 12,
|
||||
ChunkSize: 4096,
|
||||
CompressionLevel: "BEST_COMPRESSION",
|
||||
CompressionStrategy: "DEFAULT_STRATEGY",
|
||||
},
|
||||
},
|
||||
httpAssert: http.Assertion{
|
||||
Meta: http.AssertionMeta{
|
||||
TestCaseName: "case1: disable gzip output",
|
||||
TargetBackend: "web-backend",
|
||||
TargetNamespace: "higress-conformance-infra",
|
||||
},
|
||||
Request: http.AssertionRequest{
|
||||
ActualRequest: http.Request{
|
||||
Host: "foo.com",
|
||||
Path: "/foo",
|
||||
Method: "GET",
|
||||
Headers: map[string]string{
|
||||
"Accept-Encoding": "*",
|
||||
},
|
||||
},
|
||||
},
|
||||
Response: http.AssertionResponse{
|
||||
ExpectedResponseNoRequest: true,
|
||||
ExpectedResponse: http.Response{
|
||||
StatusCode: 200,
|
||||
AbsentHeaders: []string{"content-encoding"},
|
||||
},
|
||||
},
|
||||
},
|
||||
envoyAssertion: envoy.Assertion{
|
||||
Path: "configs.#.dynamic_listeners.#.active_state.listener.filter_chains",
|
||||
TargetNamespace: "higress-system",
|
||||
CheckType: envoy.CheckTypeNotExist,
|
||||
ExpectEnvoyConfig: map[string]interface{}{
|
||||
"memory_level": 5,
|
||||
"compression_level": "COMPRESSION_LEVEL_9",
|
||||
"window_bits": 12,
|
||||
"min_content_length": 1024,
|
||||
"disable_on_etag_header": true,
|
||||
"content_type": []interface{}{
|
||||
"text/html",
|
||||
"text/css",
|
||||
"text/plain",
|
||||
"text/xml",
|
||||
"application/json",
|
||||
"application/javascript",
|
||||
"application/xhtml+xml",
|
||||
"image/svg+xml",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
higressConfig: &configmap.HigressConfig{
|
||||
Gzip: &configmap.Gzip{
|
||||
Enable: true,
|
||||
MinContentLength: 100,
|
||||
ContentType: []string{"text/html", "text/css", "text/plain", "text/xml", "application/json", "application/javascript", "application/xhtml+xml", "image/svg+xml"},
|
||||
DisableOnEtagHeader: true,
|
||||
MemoryLevel: 5,
|
||||
WindowBits: 12,
|
||||
ChunkSize: 4096,
|
||||
CompressionLevel: "BEST_COMPRESSION",
|
||||
CompressionStrategy: "DEFAULT_STRATEGY",
|
||||
},
|
||||
},
|
||||
httpAssert: http.Assertion{
|
||||
Meta: http.AssertionMeta{
|
||||
TestCaseName: "case2: enable gzip output",
|
||||
TargetBackend: "web-backend",
|
||||
TargetNamespace: "higress-conformance-infra",
|
||||
},
|
||||
Request: http.AssertionRequest{
|
||||
ActualRequest: http.Request{
|
||||
Host: "foo.com",
|
||||
Path: "/foo",
|
||||
Method: "GET",
|
||||
Headers: map[string]string{
|
||||
"Accept-Encoding": "*",
|
||||
},
|
||||
},
|
||||
},
|
||||
Response: http.AssertionResponse{
|
||||
ExpectedResponseNoRequest: true,
|
||||
ExpectedResponse: http.Response{
|
||||
StatusCode: 200,
|
||||
},
|
||||
AdditionalResponseHeaders: map[string]string{"content-encoding": "gzip"},
|
||||
},
|
||||
},
|
||||
envoyAssertion: envoy.Assertion{
|
||||
Path: "configs.#.dynamic_listeners.#.active_state.listener.filter_chains",
|
||||
TargetNamespace: "higress-system",
|
||||
CheckType: envoy.CheckTypeExist,
|
||||
ExpectEnvoyConfig: map[string]interface{}{
|
||||
"name": "envoy.filters.network.http_connection_manager",
|
||||
"@type": "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager",
|
||||
"stat_prefix": "outbound_0.0.0.0_80",
|
||||
"memory_level": 5,
|
||||
"compression_level": "COMPRESSION_LEVEL_9",
|
||||
"window_bits": 12,
|
||||
"min_content_length": 100,
|
||||
"disable_on_etag_header": true,
|
||||
"content_type": []interface{}{
|
||||
"text/html",
|
||||
"text/css",
|
||||
"text/plain",
|
||||
"text/xml",
|
||||
"application/json",
|
||||
"application/javascript",
|
||||
"application/xhtml+xml",
|
||||
"image/svg+xml",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
higressConfig: &configmap.HigressConfig{
|
||||
Gzip: &configmap.Gzip{
|
||||
Enable: true,
|
||||
MinContentLength: 4096,
|
||||
ContentType: []string{"text/html", "text/css", "text/plain", "text/xml", "application/json", "application/javascript", "application/xhtml+xml", "image/svg+xml"},
|
||||
DisableOnEtagHeader: true,
|
||||
MemoryLevel: 5,
|
||||
WindowBits: 12,
|
||||
ChunkSize: 4096,
|
||||
CompressionLevel: "BEST_COMPRESSION",
|
||||
CompressionStrategy: "DEFAULT_STRATEGY",
|
||||
},
|
||||
},
|
||||
httpAssert: http.Assertion{
|
||||
Meta: http.AssertionMeta{
|
||||
TestCaseName: "case3: disable gzip output because content length less hhan 4096 ",
|
||||
TargetBackend: "web-backend",
|
||||
TargetNamespace: "higress-conformance-infra",
|
||||
},
|
||||
Request: http.AssertionRequest{
|
||||
ActualRequest: http.Request{
|
||||
Host: "foo.com",
|
||||
Path: "/foo",
|
||||
Method: "GET",
|
||||
Headers: map[string]string{
|
||||
"Accept-Encoding": "*",
|
||||
},
|
||||
},
|
||||
},
|
||||
Response: http.AssertionResponse{
|
||||
ExpectedResponseNoRequest: true,
|
||||
ExpectedResponse: http.Response{
|
||||
StatusCode: 200,
|
||||
AbsentHeaders: []string{"content-encoding"},
|
||||
},
|
||||
},
|
||||
},
|
||||
envoyAssertion: envoy.Assertion{
|
||||
Path: "configs.#.dynamic_listeners.#.active_state.listener.filter_chains",
|
||||
TargetNamespace: "higress-system",
|
||||
CheckType: envoy.CheckTypeExist,
|
||||
ExpectEnvoyConfig: map[string]interface{}{
|
||||
"name": "envoy.filters.network.http_connection_manager",
|
||||
"@type": "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager",
|
||||
"stat_prefix": "outbound_0.0.0.0_80",
|
||||
"memory_level": 5,
|
||||
"compression_level": "COMPRESSION_LEVEL_9",
|
||||
"window_bits": 12,
|
||||
"min_content_length": 4096,
|
||||
"disable_on_etag_header": true,
|
||||
"content_type": []interface{}{
|
||||
"text/html",
|
||||
"text/css",
|
||||
"text/plain",
|
||||
"text/xml",
|
||||
"application/json",
|
||||
"application/javascript",
|
||||
"application/xhtml+xml",
|
||||
"image/svg+xml",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
higressConfig: &configmap.HigressConfig{
|
||||
Gzip: &configmap.Gzip{
|
||||
Enable: true,
|
||||
MinContentLength: 100,
|
||||
ContentType: []string{"text/html", "text/css", "text/plain", "text/xml", "application/javascript", "application/xhtml+xml", "image/svg+xml"},
|
||||
DisableOnEtagHeader: true,
|
||||
MemoryLevel: 5,
|
||||
WindowBits: 12,
|
||||
ChunkSize: 4096,
|
||||
CompressionLevel: "BEST_COMPRESSION",
|
||||
CompressionStrategy: "DEFAULT_STRATEGY",
|
||||
},
|
||||
},
|
||||
httpAssert: http.Assertion{
|
||||
Meta: http.AssertionMeta{
|
||||
TestCaseName: "case4: disable gzip output because application/json missed in content types ",
|
||||
TargetBackend: "web-backend",
|
||||
TargetNamespace: "higress-conformance-infra",
|
||||
},
|
||||
Request: http.AssertionRequest{
|
||||
ActualRequest: http.Request{
|
||||
Host: "foo.com",
|
||||
Path: "/foo",
|
||||
Method: "GET",
|
||||
Headers: map[string]string{
|
||||
"Accept-Encoding": "*",
|
||||
},
|
||||
},
|
||||
},
|
||||
Response: http.AssertionResponse{
|
||||
ExpectedResponseNoRequest: true,
|
||||
ExpectedResponse: http.Response{
|
||||
StatusCode: 200,
|
||||
AbsentHeaders: []string{"content-encoding"},
|
||||
},
|
||||
},
|
||||
},
|
||||
envoyAssertion: envoy.Assertion{
|
||||
Path: "configs.#.dynamic_listeners.#.active_state.listener.filter_chains",
|
||||
TargetNamespace: "higress-system",
|
||||
CheckType: envoy.CheckTypeExist,
|
||||
ExpectEnvoyConfig: map[string]interface{}{
|
||||
"name": "envoy.filters.network.http_connection_manager",
|
||||
"@type": "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager",
|
||||
"stat_prefix": "outbound_0.0.0.0_80",
|
||||
"memory_level": 5,
|
||||
"compression_level": "COMPRESSION_LEVEL_9",
|
||||
"window_bits": 12,
|
||||
"min_content_length": 100,
|
||||
"disable_on_etag_header": true,
|
||||
"content_type": []interface{}{
|
||||
"text/html",
|
||||
"text/css",
|
||||
"text/plain",
|
||||
"text/xml",
|
||||
"application/javascript",
|
||||
"application/xhtml+xml",
|
||||
"image/svg+xml",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var ConfigmapGzip = suite.ConformanceTest{
|
||||
@@ -33,171 +294,9 @@ var ConfigmapGzip = suite.ConformanceTest{
|
||||
Manifests: []string{"tests/configmap-gzip.yaml"},
|
||||
Features: []suite.SupportedFeature{suite.HTTPConformanceFeature},
|
||||
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
|
||||
testcases := []struct {
|
||||
higressConfig *configmap.HigressConfig
|
||||
httpAssert http.Assertion
|
||||
}{
|
||||
{
|
||||
higressConfig: &configmap.HigressConfig{
|
||||
Gzip: &configmap.Gzip{
|
||||
Enable: false,
|
||||
MinContentLength: 1024,
|
||||
ContentType: []string{"text/html", "text/css", "text/plain", "text/xml", "application/json", "application/javascript", "application/xhtml+xml", "image/svg+xml"},
|
||||
DisableOnEtagHeader: true,
|
||||
MemoryLevel: 5,
|
||||
WindowBits: 12,
|
||||
ChunkSize: 4096,
|
||||
CompressionLevel: "BEST_COMPRESSION",
|
||||
CompressionStrategy: "DEFAULT_STRATEGY",
|
||||
},
|
||||
},
|
||||
httpAssert: http.Assertion{
|
||||
Meta: http.AssertionMeta{
|
||||
TestCaseName: "case1: disable gzip output",
|
||||
TargetBackend: "web-backend",
|
||||
TargetNamespace: "higress-conformance-infra",
|
||||
},
|
||||
Request: http.AssertionRequest{
|
||||
ActualRequest: http.Request{
|
||||
Host: "foo.com",
|
||||
Path: "/foo",
|
||||
Method: "GET",
|
||||
Headers: map[string]string{
|
||||
"Accept-Encoding": "*",
|
||||
},
|
||||
},
|
||||
},
|
||||
Response: http.AssertionResponse{
|
||||
ExpectedResponseNoRequest: true,
|
||||
ExpectedResponse: http.Response{
|
||||
StatusCode: 200,
|
||||
AbsentHeaders: []string{"content-encoding"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
higressConfig: &configmap.HigressConfig{
|
||||
Gzip: &configmap.Gzip{
|
||||
Enable: true,
|
||||
MinContentLength: 100,
|
||||
ContentType: []string{"text/html", "text/css", "text/plain", "text/xml", "application/json", "application/javascript", "application/xhtml+xml", "image/svg+xml"},
|
||||
DisableOnEtagHeader: true,
|
||||
MemoryLevel: 5,
|
||||
WindowBits: 12,
|
||||
ChunkSize: 4096,
|
||||
CompressionLevel: "BEST_COMPRESSION",
|
||||
CompressionStrategy: "DEFAULT_STRATEGY",
|
||||
},
|
||||
},
|
||||
httpAssert: http.Assertion{
|
||||
Meta: http.AssertionMeta{
|
||||
TestCaseName: "case2: enable gzip output",
|
||||
TargetBackend: "web-backend",
|
||||
TargetNamespace: "higress-conformance-infra",
|
||||
},
|
||||
Request: http.AssertionRequest{
|
||||
ActualRequest: http.Request{
|
||||
Host: "foo.com",
|
||||
Path: "/foo",
|
||||
Method: "GET",
|
||||
Headers: map[string]string{
|
||||
"Accept-Encoding": "*",
|
||||
},
|
||||
},
|
||||
},
|
||||
Response: http.AssertionResponse{
|
||||
ExpectedResponseNoRequest: true,
|
||||
ExpectedResponse: http.Response{
|
||||
StatusCode: 200,
|
||||
},
|
||||
AdditionalResponseHeaders: map[string]string{"content-encoding": "gzip"},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
higressConfig: &configmap.HigressConfig{
|
||||
Gzip: &configmap.Gzip{
|
||||
Enable: true,
|
||||
MinContentLength: 4096,
|
||||
ContentType: []string{"text/html", "text/css", "text/plain", "text/xml", "application/json", "application/javascript", "application/xhtml+xml", "image/svg+xml"},
|
||||
DisableOnEtagHeader: true,
|
||||
MemoryLevel: 5,
|
||||
WindowBits: 12,
|
||||
ChunkSize: 4096,
|
||||
CompressionLevel: "BEST_COMPRESSION",
|
||||
CompressionStrategy: "DEFAULT_STRATEGY",
|
||||
},
|
||||
},
|
||||
httpAssert: http.Assertion{
|
||||
Meta: http.AssertionMeta{
|
||||
TestCaseName: "case3: disable gzip output because content length less hhan 4096 ",
|
||||
TargetBackend: "web-backend",
|
||||
TargetNamespace: "higress-conformance-infra",
|
||||
},
|
||||
Request: http.AssertionRequest{
|
||||
ActualRequest: http.Request{
|
||||
Host: "foo.com",
|
||||
Path: "/foo",
|
||||
Method: "GET",
|
||||
Headers: map[string]string{
|
||||
"Accept-Encoding": "*",
|
||||
},
|
||||
},
|
||||
},
|
||||
Response: http.AssertionResponse{
|
||||
ExpectedResponseNoRequest: true,
|
||||
ExpectedResponse: http.Response{
|
||||
StatusCode: 200,
|
||||
AbsentHeaders: []string{"content-encoding"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
higressConfig: &configmap.HigressConfig{
|
||||
Gzip: &configmap.Gzip{
|
||||
Enable: true,
|
||||
MinContentLength: 100,
|
||||
ContentType: []string{"text/html", "text/css", "text/plain", "text/xml", "application/javascript", "application/xhtml+xml", "image/svg+xml"},
|
||||
DisableOnEtagHeader: true,
|
||||
MemoryLevel: 5,
|
||||
WindowBits: 12,
|
||||
ChunkSize: 4096,
|
||||
CompressionLevel: "BEST_COMPRESSION",
|
||||
CompressionStrategy: "DEFAULT_STRATEGY",
|
||||
},
|
||||
},
|
||||
httpAssert: http.Assertion{
|
||||
Meta: http.AssertionMeta{
|
||||
TestCaseName: "case4: disable gzip output because application/json missed in content types ",
|
||||
TargetBackend: "web-backend",
|
||||
TargetNamespace: "higress-conformance-infra",
|
||||
},
|
||||
Request: http.AssertionRequest{
|
||||
ActualRequest: http.Request{
|
||||
Host: "foo.com",
|
||||
Path: "/foo",
|
||||
Method: "GET",
|
||||
Headers: map[string]string{
|
||||
"Accept-Encoding": "*",
|
||||
},
|
||||
},
|
||||
},
|
||||
Response: http.AssertionResponse{
|
||||
ExpectedResponseNoRequest: true,
|
||||
ExpectedResponse: http.Response{
|
||||
StatusCode: 200,
|
||||
AbsentHeaders: []string{"content-encoding"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
t.Run("Configmap Gzip", func(t *testing.T) {
|
||||
for _, testcase := range testcases {
|
||||
err := kubernetes.ApplyConfigmapDataWithYaml(suite.Client, "higress-system", "higress-config", "higress", testcase.higressConfig)
|
||||
for _, testcase := range testCases {
|
||||
err := kubernetes.ApplyConfigmapDataWithYaml(t, suite.Client, "higress-system", "higress-config", "higress", testcase.higressConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("can't apply conifgmap %s in namespace %s for data key %s", "higress-config", "higress-system", "higress")
|
||||
}
|
||||
@@ -206,3 +305,22 @@ var ConfigmapGzip = suite.ConformanceTest{
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
var ConfigMapGzipEnvoy = suite.ConformanceTest{
|
||||
ShortName: "ConfigMapGzipEnvoy",
|
||||
Description: "The Envoy config should contain gzip config",
|
||||
Manifests: []string{"tests/configmap-gzip.yaml"},
|
||||
Features: []suite.SupportedFeature{suite.EnvoyConfigConformanceFeature},
|
||||
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
|
||||
t.Run("ConfigMap Gzip Envoy", func(t *testing.T) {
|
||||
for _, testcase := range testCases {
|
||||
// apply config
|
||||
err := kubernetes.ApplyConfigmapDataWithYaml(t, suite.Client, "higress-system", "higress-config", "higress", testcase.higressConfig)
|
||||
if err != nil {
|
||||
t.Fatalf("can't apply conifgmap %s in namespace %s for data key %s", "higress-config", "higress-system", "higress")
|
||||
}
|
||||
envoy.AssertEnvoyConfig(t, suite.TimeoutConfig, testcase.envoyAssertion)
|
||||
}
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
@@ -29,4 +29,5 @@ spec:
|
||||
service:
|
||||
name: infra-backend-v3
|
||||
port:
|
||||
number: 8080
|
||||
number: 8080
|
||||
|
||||
|
||||
Reference in New Issue
Block a user