mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 23:06:32 +00:00
Fix chunker tests
This commit is contained in:
parent
f924dc1dc6
commit
3d058929e3
@ -150,8 +150,7 @@ func get_random(seed, count int) []byte {
|
|||||||
func TestChunker(t *testing.T) {
|
func TestChunker(t *testing.T) {
|
||||||
// setup data source
|
// setup data source
|
||||||
buf := get_random(23, 32*1024*1024)
|
buf := get_random(23, 32*1024*1024)
|
||||||
ch, err := chunker.New(bytes.NewReader(buf), testPol, *testBufSize, sha256.New())
|
ch := chunker.New(bytes.NewReader(buf), testPol, *testBufSize, sha256.New())
|
||||||
ok(t, err)
|
|
||||||
chunks := test_with_data(t, ch, chunks1)
|
chunks := test_with_data(t, ch, chunks1)
|
||||||
|
|
||||||
// test reader
|
// test reader
|
||||||
@ -178,8 +177,7 @@ func TestChunker(t *testing.T) {
|
|||||||
|
|
||||||
// setup nullbyte data source
|
// setup nullbyte data source
|
||||||
buf = bytes.Repeat([]byte{0}, len(chunks2)*chunker.MinSize)
|
buf = bytes.Repeat([]byte{0}, len(chunks2)*chunker.MinSize)
|
||||||
ch, err = chunker.New(bytes.NewReader(buf), testPol, *testBufSize, sha256.New())
|
ch = chunker.New(bytes.NewReader(buf), testPol, *testBufSize, sha256.New())
|
||||||
ok(t, err)
|
|
||||||
|
|
||||||
test_with_data(t, ch, chunks2)
|
test_with_data(t, ch, chunks2)
|
||||||
}
|
}
|
||||||
@ -195,8 +193,7 @@ func TestChunkerWithRandomPolynomial(t *testing.T) {
|
|||||||
t.Logf("generating random polynomial took %v", time.Since(start))
|
t.Logf("generating random polynomial took %v", time.Since(start))
|
||||||
|
|
||||||
start = time.Now()
|
start = time.Now()
|
||||||
ch, err := chunker.New(bytes.NewReader(buf), p, *testBufSize, sha256.New())
|
ch := chunker.New(bytes.NewReader(buf), p, *testBufSize, sha256.New())
|
||||||
ok(t, err)
|
|
||||||
t.Logf("creating chunker took %v", time.Since(start))
|
t.Logf("creating chunker took %v", time.Since(start))
|
||||||
|
|
||||||
// make sure that first chunk is different
|
// make sure that first chunk is different
|
||||||
@ -213,8 +210,7 @@ func TestChunkerWithRandomPolynomial(t *testing.T) {
|
|||||||
func TestChunkerWithoutHash(t *testing.T) {
|
func TestChunkerWithoutHash(t *testing.T) {
|
||||||
// setup data source
|
// setup data source
|
||||||
buf := get_random(23, 32*1024*1024)
|
buf := get_random(23, 32*1024*1024)
|
||||||
ch, err := chunker.New(bytes.NewReader(buf), testPol, *testBufSize, nil)
|
ch := chunker.New(bytes.NewReader(buf), testPol, *testBufSize, nil)
|
||||||
ok(t, err)
|
|
||||||
chunks := test_with_data(t, ch, chunks1)
|
chunks := test_with_data(t, ch, chunks1)
|
||||||
|
|
||||||
// test reader
|
// test reader
|
||||||
@ -244,16 +240,14 @@ func TestChunkerWithoutHash(t *testing.T) {
|
|||||||
|
|
||||||
// setup nullbyte data source
|
// setup nullbyte data source
|
||||||
buf = bytes.Repeat([]byte{0}, len(chunks2)*chunker.MinSize)
|
buf = bytes.Repeat([]byte{0}, len(chunks2)*chunker.MinSize)
|
||||||
ch, err = chunker.New(bytes.NewReader(buf), testPol, *testBufSize, sha256.New())
|
ch = chunker.New(bytes.NewReader(buf), testPol, *testBufSize, sha256.New())
|
||||||
ok(t, err)
|
|
||||||
|
|
||||||
test_with_data(t, ch, chunks2)
|
test_with_data(t, ch, chunks2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChunkerReuse(t *testing.T) {
|
func TestChunkerReuse(t *testing.T) {
|
||||||
// test multiple uses of the same chunker
|
// test multiple uses of the same chunker
|
||||||
ch, err := chunker.New(nil, testPol, *testBufSize, sha256.New())
|
ch := chunker.New(nil, testPol, *testBufSize, sha256.New())
|
||||||
ok(t, err)
|
|
||||||
buf := get_random(23, 32*1024*1024)
|
buf := get_random(23, 32*1024*1024)
|
||||||
|
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
@ -289,8 +283,7 @@ func benchmarkChunker(b *testing.B, hash hash.Hash) {
|
|||||||
rd = bytes.NewReader(get_random(23, size))
|
rd = bytes.NewReader(get_random(23, size))
|
||||||
}
|
}
|
||||||
|
|
||||||
ch, err := chunker.New(rd, testPol, *testBufSize, hash)
|
ch := chunker.New(rd, testPol, *testBufSize, hash)
|
||||||
ok(b, err)
|
|
||||||
|
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
b.SetBytes(int64(size))
|
b.SetBytes(int64(size))
|
||||||
@ -339,7 +332,6 @@ func BenchmarkNewChunker(b *testing.B) {
|
|||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
_, err := chunker.New(bytes.NewBuffer(nil), p, *testBufSize, nil)
|
chunker.New(bytes.NewBuffer(nil), p, *testBufSize, nil)
|
||||||
ok(b, err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user