From ed738e842d2fbdf2d6459e39267a633c4a9b2f5d Mon Sep 17 00:00:00 2001 From: Evgenii Kliuchnikov Date: Tue, 29 Aug 2023 03:59:55 -0700 Subject: [PATCH] more sophisticated golang TestEncoderFlush PiperOrigin-RevId: 560982956 --- go/cbrotli/cbrotli_test.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/go/cbrotli/cbrotli_test.go b/go/cbrotli/cbrotli_test.go index 36ad2ba..254c0cd 100644 --- a/go/cbrotli/cbrotli_test.go +++ b/go/cbrotli/cbrotli_test.go @@ -141,7 +141,8 @@ func TestEncoderLargeInput(t *testing.T) { } func TestEncoderFlush(t *testing.T) { - input := make([]byte, 1000) + const payload = 32766 // Enough to force encoder emit 2 chunks + input := make([]byte, payload) rand.Read(input) out := bytes.Buffer{} e := NewWriter(&out, WriterOptions{Quality: 5}) @@ -156,11 +157,16 @@ func TestEncoderFlush(t *testing.T) { if out.Len() == 0 { t.Fatalf("0 bytes written after Flush()") } - decompressed := make([]byte, 1000) + decompressed := make([]byte, payload) reader := NewReader(bytes.NewReader(out.Bytes())) n, err := reader.Read(decompressed) + if n >= len(decompressed) || err != nil { + t.Errorf("Expected {<%v, nil}, but got {%v, %v}", len(decompressed), n, err) + } + m, err := reader.Read(decompressed[n:]) + n += m if n != len(decompressed) || err != nil { - t.Errorf("Expected <%v, nil>, but <%v, %v>", len(decompressed), n, err) + t.Errorf("Expected {%v, nil}, but got {%v, %v}", len(decompressed), n, err) } reader.Close() if !bytes.Equal(decompressed, input) {