From 2476a21b860e217a4d7e7e4f4566b8eca725e037 Mon Sep 17 00:00:00 2001 From: mkelvers Date: Fri, 3 Jul 2026 03:00:57 +0200 Subject: [PATCH] test: add compression test case definitions --- internal/server/static_delivery_test.go | 94 +++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/internal/server/static_delivery_test.go b/internal/server/static_delivery_test.go index 2e6be265..1610e46f 100644 --- a/internal/server/static_delivery_test.go +++ b/internal/server/static_delivery_test.go @@ -42,6 +42,100 @@ func TestStaticCacheMiddleware(t *testing.T) { } } +//nolint:unused +type compressionTestCase struct { + name string + method string + path string + acceptEncoding string + rangeHeader string + contentEncoding string + status int + contentType string + wantEncoding string + wantVary bool +} + +//nolint:unused +var compressionCases = []compressionTestCase{ + { + name: "gzip text", + method: http.MethodGet, + path: "/dist/static/app.js", + acceptEncoding: "gzip", + status: http.StatusOK, + contentType: "application/javascript", + wantEncoding: "gzip", + wantVary: true, + }, + { + name: "plain without negotiation", + method: http.MethodGet, + path: "/dist/static/app.js", + status: http.StatusOK, + contentType: "application/javascript", + wantEncoding: "", + wantVary: true, + }, + { + name: "playback stream", + method: http.MethodGet, + path: "/watch/proxy/stream", + acceptEncoding: "gzip", + status: http.StatusOK, + contentType: "application/vnd.apple.mpegurl", + wantEncoding: "", + }, + { + name: "playback subtitle", + method: http.MethodGet, + path: "/watch/proxy/subtitle", + acceptEncoding: "gzip", + status: http.StatusOK, + contentType: "text/vtt", + wantEncoding: "", + }, + { + name: "range response", + method: http.MethodGet, + path: "/media", + acceptEncoding: "gzip", + rangeHeader: "bytes=0-99", + status: http.StatusPartialContent, + contentType: "text/plain", + wantEncoding: "", + }, + { + name: "compressed image", + method: http.MethodGet, + path: "/image", + acceptEncoding: "gzip", + status: http.StatusOK, + contentType: "image/png", + wantEncoding: "", + }, + { + name: "already encoded", + method: http.MethodGet, + path: "/encoded", + acceptEncoding: "gzip", + contentEncoding: "br", + status: http.StatusOK, + contentType: "text/plain", + wantEncoding: "br", + }, + { + name: "gzip refused", + method: http.MethodGet, + path: "/text", + acceptEncoding: "br, gzip;q=0", + status: http.StatusOK, + contentType: "text/plain", + wantEncoding: "", + wantVary: true, + }, +} + //nolint:unused func headerContains(header http.Header, name, want string) bool { for _, line := range header.Values(name) {