Skip to content

Commit

Permalink
Update internal/featuretests/v3/compression_test.go
Browse files Browse the repository at this point in the history
Co-authored-by: Tero Saarni <[email protected]>
Signed-off-by: Geoff Macartney <[email protected]>
  • Loading branch information
2 people authored and Geoff Macartney committed Nov 26, 2024
1 parent 45ea946 commit 75f8b7b
Showing 1 changed file with 40 additions and 172 deletions.
212 changes: 40 additions & 172 deletions internal/featuretests/v3/compression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,62 +27,20 @@ import (
xdscache_v3 "github.com/projectcontour/contour/internal/xdscache/v3"
)

func TestDefaultCompression(t *testing.T) {
rh, c, done := setup(t)
defer done()

s1 := fixture.NewService("backend").
WithPorts(core_v1.ServicePort{Name: "http", Port: 80})
rh.OnAdd(s1)

hp1 := &contour_v1.HTTPProxy{
ObjectMeta: meta_v1.ObjectMeta{
Name: "simple",
Namespace: s1.Namespace,
},
Spec: contour_v1.HTTPProxySpec{
VirtualHost: &contour_v1.VirtualHost{
Fqdn: "example.com",
},
Routes: []contour_v1.Route{{
Conditions: matchconditions(prefixMatchCondition("/")),
Services: []contour_v1.Service{{
Name: s1.Name,
Port: 80,
}},
}},
},
func TestCompression(t *testing.T) {
tests := map[string]struct {
algorithm contour_v1alpha1.CompressionAlgorithm
want contour_v1alpha1.CompressionAlgorithm
}{
"default": {algorithm: "", want: contour_v1alpha1.GzipCompression},
"disabled": {algorithm: contour_v1alpha1.DisabledCompression, want: contour_v1alpha1.DisabledCompression},
"brotli": {algorithm: contour_v1alpha1.BrotliCompression, want: contour_v1alpha1.BrotliCompression},
"zstd": {algorithm: contour_v1alpha1.ZstdCompression, want: contour_v1alpha1.ZstdCompression},
"gzip": {algorithm: contour_v1alpha1.GzipCompression, want: contour_v1alpha1.GzipCompression},
}
rh.OnAdd(hp1)

httpListener := defaultHTTPListener()
httpListener.FilterChains = envoy_v3.FilterChains(envoy_v3.HTTPConnectionManagerBuilder().
RouteConfigName(xdscache_v3.ENVOY_HTTP_LISTENER).
MetricsPrefix(xdscache_v3.ENVOY_HTTP_LISTENER).
AccessLoggers(envoy_v3.FileAccessLogEnvoy(xdscache_v3.DEFAULT_HTTP_ACCESS_LOG, "", nil, contour_v1alpha1.LogLevelInfo)).
DefaultFilters().
Get(),
)

c.Request(listenerType, xdscache_v3.ENVOY_HTTP_LISTENER).Equals(&envoy_service_discovery_v3.DiscoveryResponse{
TypeUrl: listenerType,
Resources: resources(t, httpListener),
})
}

func TestDisableCompression(t *testing.T) {
withDisableCompression := func(conf *xdscache_v3.ListenerConfig) {
conf.Compression = &contour_v1alpha1.EnvoyCompression{
Algorithm: contour_v1alpha1.DisabledCompression,
}
}

rh, c, done := setup(t, withDisableCompression)
defer done()

s1 := fixture.NewService("backend").
WithPorts(core_v1.ServicePort{Name: "http", Port: 80})
rh.OnAdd(s1)

hp1 := &contour_v1.HTTPProxy{
ObjectMeta: meta_v1.ObjectMeta{
Expand All @@ -102,126 +60,36 @@ func TestDisableCompression(t *testing.T) {
}},
},
}
rh.OnAdd(hp1)

httpListener := defaultHTTPListener()
httpListener.FilterChains = envoy_v3.FilterChains(envoy_v3.HTTPConnectionManagerBuilder().
Compression(&contour_v1alpha1.EnvoyCompression{
Algorithm: contour_v1alpha1.DisabledCompression,
}).
RouteConfigName(xdscache_v3.ENVOY_HTTP_LISTENER).
MetricsPrefix(xdscache_v3.ENVOY_HTTP_LISTENER).
AccessLoggers(envoy_v3.FileAccessLogEnvoy(xdscache_v3.DEFAULT_HTTP_ACCESS_LOG, "", nil, contour_v1alpha1.LogLevelInfo)).
DefaultFilters().
Get(),
)

c.Request(listenerType, xdscache_v3.ENVOY_HTTP_LISTENER).Equals(&envoy_service_discovery_v3.DiscoveryResponse{
TypeUrl: listenerType,
Resources: resources(t, httpListener),
})
}

func TestBrotliCompression(t *testing.T) {
withBrotliCompression := func(conf *xdscache_v3.ListenerConfig) {
conf.Compression = &contour_v1alpha1.EnvoyCompression{
Algorithm: contour_v1alpha1.BrotliCompression,
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
rh, c, done := setup(t, func(conf *xdscache_v3.ListenerConfig) {
if tc.algorithm != "" {
conf.Compression = &contour_v1alpha1.EnvoyCompression{
Algorithm: tc.algorithm,
}
}
})
defer done()

rh.OnAdd(s1)
rh.OnAdd(hp1)
httpListener := defaultHTTPListener()
httpListener.FilterChains = envoy_v3.FilterChains(envoy_v3.HTTPConnectionManagerBuilder().
Compression(&contour_v1alpha1.EnvoyCompression{
Algorithm: tc.want,
}).
RouteConfigName(xdscache_v3.ENVOY_HTTP_LISTENER).
MetricsPrefix(xdscache_v3.ENVOY_HTTP_LISTENER).
AccessLoggers(envoy_v3.FileAccessLogEnvoy(xdscache_v3.DEFAULT_HTTP_ACCESS_LOG, "", nil, contour_v1alpha1.LogLevelInfo)).
DefaultFilters().
Get(),
)

c.Request(listenerType, xdscache_v3.ENVOY_HTTP_LISTENER).Equals(&envoy_service_discovery_v3.DiscoveryResponse{
TypeUrl: listenerType,
Resources: resources(t, httpListener),
})
})
}

rh, c, done := setup(t, withBrotliCompression)
defer done()

s1 := fixture.NewService("backend").
WithPorts(core_v1.ServicePort{Name: "http", Port: 80})
rh.OnAdd(s1)

hp1 := &contour_v1.HTTPProxy{
ObjectMeta: meta_v1.ObjectMeta{
Name: "simple",
Namespace: s1.Namespace,
},
Spec: contour_v1.HTTPProxySpec{
VirtualHost: &contour_v1.VirtualHost{
Fqdn: "example.com",
},
Routes: []contour_v1.Route{{
Conditions: matchconditions(prefixMatchCondition("/")),
Services: []contour_v1.Service{{
Name: s1.Name,
Port: 80,
}},
}},
},
}
rh.OnAdd(hp1)

httpListener := defaultHTTPListener()
httpListener.FilterChains = envoy_v3.FilterChains(envoy_v3.HTTPConnectionManagerBuilder().
Compression(&contour_v1alpha1.EnvoyCompression{
Algorithm: contour_v1alpha1.BrotliCompression,
}).
RouteConfigName(xdscache_v3.ENVOY_HTTP_LISTENER).
MetricsPrefix(xdscache_v3.ENVOY_HTTP_LISTENER).
AccessLoggers(envoy_v3.FileAccessLogEnvoy(xdscache_v3.DEFAULT_HTTP_ACCESS_LOG, "", nil, contour_v1alpha1.LogLevelInfo)).
DefaultFilters().
Get(),
)

c.Request(listenerType, xdscache_v3.ENVOY_HTTP_LISTENER).Equals(&envoy_service_discovery_v3.DiscoveryResponse{
TypeUrl: listenerType,
Resources: resources(t, httpListener),
})
}

func TestZstdCompression(t *testing.T) {
withZstdCompression := func(conf *xdscache_v3.ListenerConfig) {
conf.Compression = &contour_v1alpha1.EnvoyCompression{
Algorithm: contour_v1alpha1.ZstdCompression,
}
}

rh, c, done := setup(t, withZstdCompression)
defer done()

s1 := fixture.NewService("backend").
WithPorts(core_v1.ServicePort{Name: "http", Port: 80})
rh.OnAdd(s1)

hp1 := &contour_v1.HTTPProxy{
ObjectMeta: meta_v1.ObjectMeta{
Name: "simple",
Namespace: s1.Namespace,
},
Spec: contour_v1.HTTPProxySpec{
VirtualHost: &contour_v1.VirtualHost{
Fqdn: "example.com",
},
Routes: []contour_v1.Route{{
Conditions: matchconditions(prefixMatchCondition("/")),
Services: []contour_v1.Service{{
Name: s1.Name,
Port: 80,
}},
}},
},
}
rh.OnAdd(hp1)

httpListener := defaultHTTPListener()
httpListener.FilterChains = envoy_v3.FilterChains(envoy_v3.HTTPConnectionManagerBuilder().
Compression(&contour_v1alpha1.EnvoyCompression{
Algorithm: contour_v1alpha1.ZstdCompression,
}).
RouteConfigName(xdscache_v3.ENVOY_HTTP_LISTENER).
MetricsPrefix(xdscache_v3.ENVOY_HTTP_LISTENER).
AccessLoggers(envoy_v3.FileAccessLogEnvoy(xdscache_v3.DEFAULT_HTTP_ACCESS_LOG, "", nil, contour_v1alpha1.LogLevelInfo)).
DefaultFilters().
Get(),
)

c.Request(listenerType, xdscache_v3.ENVOY_HTTP_LISTENER).Equals(&envoy_service_discovery_v3.DiscoveryResponse{
TypeUrl: listenerType,
Resources: resources(t, httpListener),
})
}

0 comments on commit 75f8b7b

Please sign in to comment.