Debian Codegraph @

debian/patches/0004-Compute-zlib-output-in-tests-instead-of-hardcoding-i.patch

raw
1 From: Paulo Gomes <[email protected]>
2 Date: Mon, 7 Sep 2026 20:50:39 +0100
3 Subject: *: Compute zlib output in tests instead of hardcoding it
4
5 Go 1.27 changed the deflate output for small inputs: the stored-block
6 sync marker is no longer emitted on close. That broke two tests which
7 hardcoded the zlib bytes of an empty object and the size of a loose
8 object file. Compress the same content within the test and compare
9 against that, so the assertions hold across toolchains.
10
11 Origin: backport, https://github.com/go-git/go-git/commit/4ae786a01dfb96289854ddc6460981531a6fe53c
12 Bug-Debian: https://bugs.debian.org/1146194
13 Forwarded: not-needed
14 Last-Update: 2026-09-07
15 ---
16 plumbing/format/packfile/encoder_test.go | 10 +++++++---
17 storage/filesystem/dotgit/dotgit_test.go | 18 +++++++++++++++---
18 2 files changed, 22 insertions(+), 6 deletions(-)
19
20 diff --git a/plumbing/format/packfile/encoder_test.go b/plumbing/format/packfile/encoder_test.go
21 index 6719f37..0c1360e 100644
22 --- a/plumbing/format/packfile/encoder_test.go
23 +++ b/plumbing/format/packfile/encoder_test.go
24 @@ -2,6 +2,7 @@ package packfile
25
26 import (
27 "bytes"
28 + "compress/zlib"
29 "io"
30
31 "github.com/go-git/go-git/v5/plumbing"
32 @@ -59,9 +60,12 @@ func (s *EncoderSuite) TestCorrectPackWithOneEmptyObject(c *C) {
33 // OBJECT HEADER(TYPE + SIZE)= 0001 0000
34 expectedResult = append(expectedResult, []byte{16}...)
35
36 - // Zlib header
37 - expectedResult = append(expectedResult,
38 - []byte{120, 156, 1, 0, 0, 255, 255, 0, 0, 0, 1}...)
39 + // Zlib stream of the empty object contents. The exact bytes depend on the
40 + // compress/flate implementation, so compress it here instead of hardcoding.
41 + var zbuf bytes.Buffer
42 + zw := zlib.NewWriter(&zbuf)
43 + c.Assert(zw.Close(), IsNil)
44 + expectedResult = append(expectedResult, zbuf.Bytes()...)
45
46 // + HASH
47 hb := [hash.Size]byte(h)
48 diff --git a/storage/filesystem/dotgit/dotgit_test.go b/storage/filesystem/dotgit/dotgit_test.go
49 index 05ea59f..feca9df 100644
50 --- a/storage/filesystem/dotgit/dotgit_test.go
51 +++ b/storage/filesystem/dotgit/dotgit_test.go
52 @@ -2,6 +2,8 @@ package dotgit
53
54 import (
55 "bufio"
56 + "bytes"
57 + "compress/zlib"
58 "encoding/hex"
59 "errors"
60 "io"
61 @@ -732,6 +734,16 @@ func (s *SuiteDotGit) TestObjectPackNotFound(c *C) {
62 c.Assert(idx, IsNil)
63 }
64
65 +func looseObjectSize(t require.TestingT, content string) int64 {
66 + var buf bytes.Buffer
67 + w := zlib.NewWriter(&buf)
68 + _, err := w.Write([]byte(content))
69 + require.NoError(t, err)
70 + require.NoError(t, w.Close())
71 +
72 + return int64(buf.Len())
73 +}
74 +
75 func (s *SuiteDotGit) TestNewObject(c *C) {
76 fs := s.TemporalFilesystem(c)
77
78 @@ -752,7 +764,7 @@ func (s *SuiteDotGit) TestNewObject(c *C) {
79
80 i, err := fs.Stat("objects/a8/a940627d132695a9769df883f85992f0ff4a43")
81 c.Assert(err, IsNil)
82 - c.Assert(i.Size(), Equals, int64(34))
83 + c.Assert(i.Size(), Equals, looseObjectSize(c, "blob 14\x00this is a test"))
84 }
85
86 func (s *SuiteDotGit) TestObjects(c *C) {
87 @@ -1302,7 +1314,7 @@ func TestIssue55(t *testing.T) {
88 writeObject(tc.fs)
89 i, err := tc.fs.Stat(path)
90 require.NoError(t, err)
91 - assert.Equal(t, int64(34), i.Size())
92 + assert.Equal(t, looseObjectSize(t, "blob 14\x00this is a test"), i.Size())
93
94 ro, err := isReadOnly(tc.fs, path)
95 require.NoError(t, err)
96 @@ -1312,7 +1324,7 @@ func TestIssue55(t *testing.T) {
97 writeObject(tc.fs)
98 i, err = tc.fs.Stat(path)
99 require.NoError(t, err)
100 - assert.Equal(t, int64(34), i.Size())
101 + assert.Equal(t, looseObjectSize(t, "blob 14\x00this is a test"), i.Size())
102
103 ro, err = isReadOnly(tc.fs, path)
104 require.NoError(t, err)