-
Notifications
You must be signed in to change notification settings - Fork 0
/
chunker_test.go
43 lines (33 loc) · 921 Bytes
/
chunker_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package fastcdc
import (
"bytes"
"crypto/rand"
"io"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestChunkerNext(t *testing.T) {
var input bytes.Buffer
var reader io.Reader
reader = io.LimitReader(rand.Reader, 4096)
reader = io.TeeReader(reader, &input)
options, err := WithAverageSize(256, 2)
require.NoError(t, err)
chunker, err := NewChunker(reader, options)
require.NoError(t, err)
var output []byte
for {
chunk, err := chunker.Next()
require.NoError(t, err)
output = append(output, chunk...)
if !chunker.HasNext() {
break
}
assert.True(t, len(chunk) <= options.maxSize, "maxSize=%d len=%d", options.maxSize, len(chunk))
assert.True(t, len(chunk) >= options.minSize, "minSize=%d len=%d", options.minSize, len(chunk))
}
expect, err := io.ReadAll(&input)
require.NoError(t, err)
assert.True(t, bytes.Equal(expect, output))
}