import "github.com/stratumn/go-core/store/storetesting"
Package storetesting defines helpers to test stores.
mock_batch.go mockadapter.go storetesting.go
type MockAdapter struct { // The mock for the GetInfo function. MockGetInfo MockGetInfo // The mock for the MockAddStoreEventChannel function. MockAddStoreEventChannel MockAddStoreEventChannel // The mock for the CreateLink function MockCreateLink MockCreateLink // The mock for the AddEvidence function MockAddEvidence MockAddEvidence // The mock for the GetSegment function. MockGetSegment MockGetSegment // The mock for the GetEvidences function MockGetEvidences MockGetEvidences // The mock for the FindSegments function. MockFindSegments MockFindSegments // The mock for the GetMapIDs function. MockGetMapIDs MockGetMapIDs // The mock for the NewBatch function. MockNewBatch MockNewBatch }
MockAdapter is used to mock a store. It implements github.com/stratumn/go-core/store.Adapter.
This example shows how to use a mock adapter.
Code:
// Create a mock. m := storetesting.MockAdapter{} // Define a GetInfo function for our mock. m.MockGetInfo.Fn = func() (interface{}, error) { return map[string]string{ "name": "test", }, nil } // Execute GetInfo on the mock. i, err := m.GetInfo(context.Background()) if err != nil { log.Fatal(err) } name := i.(map[string]string)["name"] // This is the number of times GetInfo was called. calledCount := m.MockGetInfo.CalledCount fmt.Printf("%s %d", name, calledCount)
Output:
test 1
func (a *MockAdapter) AddEvidence(ctx context.Context, linkHash chainscript.LinkHash, evidence *chainscript.Evidence) error
AddEvidence implements github.com/stratumn/go-core/store.Adapter.AddEvidence.
func (a *MockAdapter) AddStoreEventChannel(storeChan chan *store.Event)
AddStoreEventChannel implements github.com/stratumn/go-core/store.Adapter.AddStoreEventChannel.
func (a *MockAdapter) CreateLink(ctx context.Context, link *chainscript.Link) (chainscript.LinkHash, error)
CreateLink implements github.com/stratumn/go-core/store.Adapter.CreateLink.
func (a *MockAdapter) FindSegments(ctx context.Context, filter *store.SegmentFilter) (*types.PaginatedSegments, error)
FindSegments implements github.com/stratumn/go-core/store.Adapter.FindSegments.
func (a *MockAdapter) GetEvidences(ctx context.Context, linkHash chainscript.LinkHash) (types.EvidenceSlice, error)
GetEvidences implements github.com/stratumn/go-core/store.Adapter.GetEvidences.
func (a *MockAdapter) GetInfo(ctx context.Context) (interface{}, error)
GetInfo implements github.com/stratumn/go-core/store.Adapter.GetInfo.
GetMapIDs implements github.com/stratumn/go-core/store.Adapter.GetMapIDs.
func (a *MockAdapter) GetSegment(ctx context.Context, linkHash chainscript.LinkHash) (*chainscript.Segment, error)
GetSegment implements github.com/stratumn/go-core/store.Adapter.GetSegment.
NewBatch implements github.com/stratumn/go-core/store.Adapter.NewBatch.
type MockAddEvidence struct { // The number of times the function was called. CalledCount int // The evidence that was passed to each call. CalledWith []*chainscript.Evidence // The last evidence that was passed. LastCalledWith *chainscript.Evidence // An optional implementation of the function. Fn func(linkHash chainscript.LinkHash, evidence *chainscript.Evidence) error }
MockAddEvidence mocks the AddEvidence function.
type MockAddStoreEventChannel struct { // The number of times the function was called. CalledCount int // The event that was passed to each call. CalledWith []chan *store.Event // The last event that was passed. LastCalledWith chan *store.Event // An optional implementation of the function. Fn func(chan *store.Event) }
MockAddStoreEventChannel mocks the AddStoreEventChannel function.
type MockBatch struct { // The mock for the CreateLink function. MockCreateLink MockBatchCreateLink // The mock for the Write function. MockWrite MockBatchWrite // The mock for the GetSegment function. MockGetSegment MockBatchGetSegment // The mock for the FindSegments function. MockFindSegments MockBatchFindSegments // The mock for the GetMapIDs function. MockGetMapIDs MockBatchGetMapIDs }
MockBatch is used to mock a batch. It implements github.com/stratumn/go-core/store.Batch
func (a *MockBatch) CreateLink(ctx context.Context, link *chainscript.Link) (chainscript.LinkHash, error)
CreateLink implements github.com/stratumn/go-core/store.Batch.CreateLink.
func (a *MockBatch) FindSegments(ctx context.Context, filter *store.SegmentFilter) (*types.PaginatedSegments, error)
FindSegments delegates the call to a underlying store
GetMapIDs delegates the call to a underlying store
func (a *MockBatch) GetSegment(ctx context.Context, linkHash chainscript.LinkHash) (*chainscript.Segment, error)
GetSegment delegates the call to a underlying store
Write implements github.com/stratumn/go-core/store.Batch.Write.
type MockBatchCreateLink struct { // The number of times the function was called. CalledCount int // The link that was passed to each call. CalledWith []*chainscript.Link // The last link that was passed. LastCalledWith *chainscript.Link // An optional implementation of the function. Fn func(*chainscript.Link) (chainscript.LinkHash, error) }
MockBatchCreateLink mocks the CreateLink function.
type MockBatchFindSegments struct { // The number of times the function was called. CalledCount int // An optional implementation of the function. Fn func(filter *store.SegmentFilter) (*types.PaginatedSegments, error) }
MockBatchFindSegments mocks the FindSegments function.
type MockBatchGetMapIDs struct { // The number of times the function was called. CalledCount int // An optional implementation of the function. Fn func(filter *store.MapFilter) ([]string, error) }
MockBatchGetMapIDs mocks the GetMapIDs function.
type MockBatchGetSegment struct { // The number of times the function was called. CalledCount int // An optional implementation of the function. Fn func(linkHash chainscript.LinkHash) (*chainscript.Segment, error) }
MockBatchGetSegment mocks the GetSegment function.
type MockBatchWrite struct { // The number of times the function was called. CalledCount int // An optional implementation of the function. Fn func() error }
MockBatchWrite mocks the Write function.
type MockCreateLink struct { // The number of times the function was called. CalledCount int // The link that was passed to each call. CalledWith []*chainscript.Link // The last link that was passed. LastCalledWith *chainscript.Link // An optional implementation of the function. Fn func(*chainscript.Link) (chainscript.LinkHash, error) }
MockCreateLink mocks the CreateLink function.
type MockDeleteValue struct { // The number of times the function was called. CalledCount int // The key that was passed to each call. CalledWith [][]byte // The last link hash that was passed. LastCalledWith []byte // An optional implementation of the function. Fn func([]byte) ([]byte, error) }
MockDeleteValue mocks the DeleteValue function.
type MockFindSegments struct { // The number of times the function was called. CalledCount int // The filter that was passed to each call. CalledWith []*store.SegmentFilter // The last filter that was passed. LastCalledWith *store.SegmentFilter // An optional implementation of the function. Fn func(*store.SegmentFilter) (*types.PaginatedSegments, error) }
MockFindSegments mocks the FindSegments function.
type MockGetEvidences struct { // The number of times the function was called. CalledCount int // The link hash that was passed to each call. CalledWith []chainscript.LinkHash // The last link hash that was passed. LastCalledWith chainscript.LinkHash // An optional implementation of the function. Fn func(chainscript.LinkHash) (types.EvidenceSlice, error) }
MockGetEvidences mocks the GetEvidences function.
type MockGetInfo struct { // The number of times the function was called. CalledCount int // An optional implementation of the function. Fn func() (interface{}, error) }
MockGetInfo mocks the GetInfo function.
type MockGetMapIDs struct { // The number of times the function was called. CalledCount int // The pagination that was passed to each call. CalledWith []*store.MapFilter // The last pagination that was passed. LastCalledWith *store.MapFilter // An optional implementation of the function. Fn func(*store.MapFilter) ([]string, error) }
MockGetMapIDs mocks the GetMapIDs function.
type MockGetSegment struct { // The number of times the function was called. CalledCount int // The link hash that was passed to each call. CalledWith []chainscript.LinkHash // The last link hash that was passed. LastCalledWith chainscript.LinkHash // An optional implementation of the function. Fn func(chainscript.LinkHash) (*chainscript.Segment, error) }
MockGetSegment mocks the GetSegment function.
type MockGetValue struct { // The number of times the function was called. CalledCount int // The link hash that was passed to each call. CalledWith [][]byte // The last link hash that was passed. LastCalledWith []byte // An optional implementation of the function. Fn func([]byte) ([]byte, error) }
MockGetValue mocks the GetValue function.
type MockKeyValueStore struct { // The mock for the SetValue function. MockSetValue MockSetValue // The mock for the GetValue function. MockGetValue MockGetValue // The mock for the DeleteValue function. MockDeleteValue MockDeleteValue }
MockKeyValueStore is used to mock a key-value store. It implements github.com/stratumn/go-core/store.KeyValueStore.
DeleteValue implements github.com/stratumn/go-core/store.KeyValueStore.DeleteValue.
GetValue implements github.com/stratumn/go-core/store.KeyValueStore.GetValue.
SetValue implements github.com/stratumn/go-core/store.KeyValueStore.SetValue.
type MockNewBatch struct { // The number of times the function was called. CalledCount int // An optional implementation of the function. Fn func() (store.Batch, error) }
MockNewBatch mocks the NewBatch function.
type MockSetValue struct { // The number of times the function was called. CalledCount int // The segment that was passed to each call. CalledWith [][][]byte // The last segment that was passed. LastCalledWith [][]byte // An optional implementation of the function. Fn func(key, value []byte) error }
MockSetValue mocks the SetValue function.
Package storetesting imports 4 packages (graph). Updated 2019-04-28. Refresh now. Tools for package owners.