Files
dolt/chunks/test_utils.go
Rafael Weinstein 591026bcfa Chunk
2015-09-21 13:24:41 -07:00

48 lines
905 B
Go

package chunks
import (
"sync"
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
"github.com/attic-labs/noms/ref"
)
func assertInputInStore(input string, ref ref.Ref, s ChunkStore, assert *assert.Assertions) {
chunk := s.Get(ref)
assert.False(chunk.IsEmpty())
assert.Equal(input, string(chunk.Data()))
}
func assertInputNotInStore(input string, ref ref.Ref, s ChunkStore, assert *assert.Assertions) {
data := s.Get(ref)
assert.Nil(data)
}
type TestStore struct {
MemoryStore
Reads int
Writes int
}
func NewTestStore() *TestStore {
return &TestStore{
MemoryStore: MemoryStore{
mu: &sync.Mutex{},
},
}
}
func (s *TestStore) Get(ref ref.Ref) Chunk {
s.Reads++
return s.MemoryStore.Get(ref)
}
func (s *TestStore) Has(ref ref.Ref) bool {
return s.MemoryStore.Has(ref)
}
func (s *TestStore) Put(c Chunk) {
s.Writes++
s.MemoryStore.Put(c)
}