From 169f5b714cc27528d7ca8c1564e0a769e1b84ff9 Mon Sep 17 00:00:00 2001 From: Mikel Olasagasti Uranga Date: Tue, 14 Jul 2026 22:10:43 +0200 Subject: [PATCH] serve/http: compare zip test output semantically Go 1.27 changes compress/flate output, which also changes archive/zip byte output. The HTTP zip download tests currently compare raw zip bytes against golden files, so they fail even though the generated zip archives contain the expected files. Compare zip entries and decompressed contents instead of the exact compressed byte stream. Signed-off-by: Mikel Olasagasti Uranga --- cmd/serve/http/http_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/cmd/serve/http/http_test.go b/cmd/serve/http/http_test.go index 1a94b0d65..a3dada7cd 100644 --- a/cmd/serve/http/http_test.go +++ b/cmd/serve/http/http_test.go @@ -1,6 +1,8 @@ package http import ( + "archive/zip" + "bytes" "compress/gzip" "context" "flag" @@ -25,6 +27,11 @@ import ( "github.com/stretchr/testify/require" ) +type zipEntry struct { + IsDir bool + Contents string +} + var ( updateGolden = flag.Bool("updategolden", false, "update golden files for regression test") ) @@ -102,12 +109,39 @@ func checkGolden(t *testing.T, fileName string, got []byte) { } else { want, err := os.ReadFile(fileName) require.NoError(t, err) + if strings.HasSuffix(fileName, ".zip") { + assert.Equal(t, readZip(t, want), readZip(t, got), fileName) + return + } wants := strings.Split(string(want), "\n") gots := strings.Split(string(got), "\n") assert.Equal(t, wants, gots, fileName) } } +func readZip(t *testing.T, data []byte) map[string]zipEntry { + t.Helper() + zr, err := zip.NewReader(bytes.NewReader(data), int64(len(data))) + require.NoError(t, err) + + entries := make(map[string]zipEntry, len(zr.File)) + for _, f := range zr.File { + entry := zipEntry{ + IsDir: f.FileInfo().IsDir(), + } + if !entry.IsDir { + rc, err := f.Open() + require.NoError(t, err) + contents, err := io.ReadAll(rc) + require.NoError(t, err) + require.NoError(t, rc.Close()) + entry.Contents = string(contents) + } + entries[f.Name] = entry + } + return entries +} + func testGET(t *testing.T, useProxy bool) { ctx := context.Background() // ci := fs.GetConfig(ctx)