From 8406bb3a77276ee4b21b8a250dfab38600c3a5a5 Mon Sep 17 00:00:00 2001 From: mesh-tools Date: Tue, 20 Oct 2026 20:38:47 +0000 Subject: [PATCH] Compare Pack's tar stream with the build agent's, since gzip's bytes differ between Go versions (issue 1479) --- go/buildstep/pack_test.go | 31 +++++++++++++++++------ go/buildstep/testdata/pack-golden.tar.gz | Bin 182 -> 0 bytes 2 files changed, 23 insertions(+), 8 deletions(-) delete mode 100644 go/buildstep/testdata/pack-golden.tar.gz diff --git a/go/buildstep/pack_test.go b/go/buildstep/pack_test.go index 3f5282d..d789052 100644 --- a/go/buildstep/pack_test.go +++ b/go/buildstep/pack_test.go @@ -2,8 +2,10 @@ package buildstep import ( "bytes" + "compress/gzip" "crypto/sha256" "encoding/hex" + "io" "os" "path/filepath" "testing" @@ -33,11 +35,13 @@ func fixture(t *testing.T) string { return root } -// 1479/AC1: the archive equals the bytes mesh-controller's pack makes for this tree. testdata/pack-golden.tar.gz -// was made once by running mesh-controller internal/builder/builder.go pack (origin/main 073ccc29, :1351-1425) -// on this fixture (fixture above, modes set by chmod). +// 1479/AC1: the tar stream inside the archive equals the bytes mesh-controller's pack makes for this tree. +// testdata/pack-golden.tar is the uncompressed stream, made once by running mesh-controller +// internal/builder/builder.go pack (origin/main 073ccc29, :1351-1425) on this fixture (above, modes set by chmod) +// and gunzipping its archive. The gzip layer is not compared byte for byte, since compress/gzip's output differs +// between Go versions; its header is checked to carry no name, no comment and no time. func TestPackEqualsTheBuildAgentsArchive(t *testing.T) { - golden, err := os.ReadFile("testdata/pack-golden.tar.gz") + golden, err := os.ReadFile("testdata/pack-golden.tar") if err != nil { t.Fatal(err) } @@ -45,12 +49,23 @@ func TestPackEqualsTheBuildAgentsArchive(t *testing.T) { if err != nil { t.Fatal(err) } - if !bytes.Equal(archive, golden) { - t.Errorf("the archive is %d bytes, the build agent's %d, and they differ", len(archive), len(golden)) + zr, err := gzip.NewReader(bytes.NewReader(archive)) + if err != nil { + t.Fatal(err) } - sum := sha256.Sum256(golden) + if zr.Name != "" || zr.Comment != "" || !zr.ModTime.IsZero() { + t.Errorf("gzip header = name %q, comment %q, time %v; want none", zr.Name, zr.Comment, zr.ModTime) + } + tarBytes, err := io.ReadAll(zr) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(tarBytes, golden) { + t.Errorf("the tar stream is %d bytes, the build agent's %d, and they differ", len(tarBytes), len(golden)) + } + sum := sha256.Sum256(archive) if digest != "sha256:"+hex.EncodeToString(sum[:]) { - t.Errorf("digest = %s", digest) + t.Errorf("digest = %s, not the sha256 of the archive", digest) } } diff --git a/go/buildstep/testdata/pack-golden.tar.gz b/go/buildstep/testdata/pack-golden.tar.gz deleted file mode 100644 index e5ea0a8420d04b076252552dbfca36625b1783e4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 182 zcmV;n07?HJiwFP!00000|Ll~p3d0}}hMn^iDcy5_t)|aoLcuI4L_^Knm(ZGm9Xb?4 z!TbK<^aOSJ&d@ZEjk6*n0C3S-;7M8mDc|e0e}ZnMs1Yy7$?UwD1b%*N`~0iM{-1L^ zP&bU^Y<2DJt+qoIPnZ%g6dE6V+-70*p;c;ABdGvB{8v)5|9ki!*!QA*Pt#FPOXdmi k-G7z(-|92_zlZ;KyYK`kdIE4boKo``0CCQ}QveVE07`{fK>z>%