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 e5ea0a8..0000000 Binary files a/go/buildstep/testdata/pack-golden.tar.gz and /dev/null differ