Skip to content

Commit

Permalink
more sophisticated golang TestEncoderFlush
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 560982956
  • Loading branch information
eustas authored and Copybara-Service committed Aug 29, 2023
1 parent e7313b0 commit ed738e8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions go/cbrotli/cbrotli_test.go
Expand Up @@ -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})
Expand All @@ -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) {
Expand Down

0 comments on commit ed738e8

Please sign in to comment.