From: Paulo Gomes Date: Mon, 7 Sep 2026 20:50:39 +0100 Subject: *: Compute zlib output in tests instead of hardcoding it Go 1.27 changed the deflate output for small inputs: the stored-block sync marker is no longer emitted on close. That broke two tests which hardcoded the zlib bytes of an empty object and the size of a loose object file. Compress the same content within the test and compare against that, so the assertions hold across toolchains. Origin: backport, https://github.com/go-git/go-git/commit/4ae786a01dfb96289854ddc6460981531a6fe53c Bug-Debian: https://bugs.debian.org/1146194 Forwarded: not-needed Last-Update: 2026-09-07 --- plumbing/format/packfile/encoder_test.go | 10 +++++++--- storage/filesystem/dotgit/dotgit_test.go | 18 +++++++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/plumbing/format/packfile/encoder_test.go b/plumbing/format/packfile/encoder_test.go index 6719f37..0c1360e 100644 --- a/plumbing/format/packfile/encoder_test.go +++ b/plumbing/format/packfile/encoder_test.go @@ -2,6 +2,7 @@ package packfile import ( "bytes" + "compress/zlib" "io" "github.com/go-git/go-git/v5/plumbing" @@ -59,9 +60,12 @@ func (s *EncoderSuite) TestCorrectPackWithOneEmptyObject(c *C) { // OBJECT HEADER(TYPE + SIZE)= 0001 0000 expectedResult = append(expectedResult, []byte{16}...) - // Zlib header - expectedResult = append(expectedResult, - []byte{120, 156, 1, 0, 0, 255, 255, 0, 0, 0, 1}...) + // Zlib stream of the empty object contents. The exact bytes depend on the + // compress/flate implementation, so compress it here instead of hardcoding. + var zbuf bytes.Buffer + zw := zlib.NewWriter(&zbuf) + c.Assert(zw.Close(), IsNil) + expectedResult = append(expectedResult, zbuf.Bytes()...) // + HASH hb := [hash.Size]byte(h) diff --git a/storage/filesystem/dotgit/dotgit_test.go b/storage/filesystem/dotgit/dotgit_test.go index 05ea59f..feca9df 100644 --- a/storage/filesystem/dotgit/dotgit_test.go +++ b/storage/filesystem/dotgit/dotgit_test.go @@ -2,6 +2,8 @@ package dotgit import ( "bufio" + "bytes" + "compress/zlib" "encoding/hex" "errors" "io" @@ -732,6 +734,16 @@ func (s *SuiteDotGit) TestObjectPackNotFound(c *C) { c.Assert(idx, IsNil) } +func looseObjectSize(t require.TestingT, content string) int64 { + var buf bytes.Buffer + w := zlib.NewWriter(&buf) + _, err := w.Write([]byte(content)) + require.NoError(t, err) + require.NoError(t, w.Close()) + + return int64(buf.Len()) +} + func (s *SuiteDotGit) TestNewObject(c *C) { fs := s.TemporalFilesystem(c) @@ -752,7 +764,7 @@ func (s *SuiteDotGit) TestNewObject(c *C) { i, err := fs.Stat("objects/a8/a940627d132695a9769df883f85992f0ff4a43") c.Assert(err, IsNil) - c.Assert(i.Size(), Equals, int64(34)) + c.Assert(i.Size(), Equals, looseObjectSize(c, "blob 14\x00this is a test")) } func (s *SuiteDotGit) TestObjects(c *C) { @@ -1302,7 +1314,7 @@ func TestIssue55(t *testing.T) { writeObject(tc.fs) i, err := tc.fs.Stat(path) require.NoError(t, err) - assert.Equal(t, int64(34), i.Size()) + assert.Equal(t, looseObjectSize(t, "blob 14\x00this is a test"), i.Size()) ro, err := isReadOnly(tc.fs, path) require.NoError(t, err) @@ -1312,7 +1324,7 @@ func TestIssue55(t *testing.T) { writeObject(tc.fs) i, err = tc.fs.Stat(path) require.NoError(t, err) - assert.Equal(t, int64(34), i.Size()) + assert.Equal(t, looseObjectSize(t, "blob 14\x00this is a test"), i.Size()) ro, err = isReadOnly(tc.fs, path) require.NoError(t, err)