mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-21 18:19:36 -06:00
stretchr has fixed a bug with the -count flag. I could merge these changes into attic-labs, but it's easier to just use strechr. We forked stretchr a long time ago so that we didn't link in the HTTP testing libraries into the noms binaries (because we were using d.Chk in production code). The HTTP issue doesn't seem to happen anymore, even though we're still using d.Chk.
85 lines
2.0 KiB
Go
85 lines
2.0 KiB
Go
// Copyright 2017 Attic Labs, Inc. All rights reserved.
|
|
// Licensed under the Apache License, version 2.0:
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
package nbs
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestAWSChunkSource(t *testing.T) {
|
|
chunks := [][]byte{
|
|
[]byte("hello2"),
|
|
[]byte("goodbye2"),
|
|
[]byte("badbye2"),
|
|
}
|
|
tableData, h := buildTable(chunks)
|
|
|
|
s3 := makeFakeS3(t)
|
|
ddb := makeFakeDDB(t)
|
|
|
|
s3or := &s3ObjectReader{s3, "bucket", nil, nil}
|
|
dts := &ddbTableStore{ddb, "table", nil, nil}
|
|
|
|
makeSrc := func(chunkMax int, ic *indexCache) chunkSource {
|
|
return newAWSChunkSource(
|
|
dts,
|
|
s3or,
|
|
awsLimits{itemMax: maxDynamoItemSize, chunkMax: uint32(chunkMax)},
|
|
h,
|
|
uint32(len(chunks)),
|
|
ic,
|
|
&Stats{},
|
|
)
|
|
}
|
|
|
|
t.Run("Dynamo", func(t *testing.T) {
|
|
ddb.putData(fmtTableName(h), tableData)
|
|
|
|
t.Run("NoIndexCache", func(t *testing.T) {
|
|
src := makeSrc(len(chunks)+1, nil)
|
|
assertChunksInReader(chunks, src, assert.New(t))
|
|
})
|
|
|
|
t.Run("WithIndexCache", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
index := parseTableIndex(tableData)
|
|
cache := newIndexCache(1024)
|
|
cache.put(h, index)
|
|
|
|
baseline := ddb.numGets
|
|
src := makeSrc(len(chunks)+1, cache)
|
|
|
|
// constructing the table reader shouldn't have resulted in any reads
|
|
assert.Zero(ddb.numGets - baseline)
|
|
assertChunksInReader(chunks, src, assert)
|
|
})
|
|
})
|
|
|
|
t.Run("S3", func(t *testing.T) {
|
|
s3.data[h.String()] = tableData
|
|
|
|
t.Run("NoIndexCache", func(t *testing.T) {
|
|
src := makeSrc(len(chunks)-1, nil)
|
|
assertChunksInReader(chunks, src, assert.New(t))
|
|
})
|
|
|
|
t.Run("WithIndexCache", func(t *testing.T) {
|
|
assert := assert.New(t)
|
|
index := parseTableIndex(tableData)
|
|
cache := newIndexCache(1024)
|
|
cache.put(h, index)
|
|
|
|
baseline := s3.getCount
|
|
src := makeSrc(len(chunks)-1, cache)
|
|
|
|
// constructing the table reader shouldn't have resulted in any reads
|
|
assert.Zero(s3.getCount - baseline)
|
|
assertChunksInReader(chunks, src, assert)
|
|
})
|
|
})
|
|
}
|