Documentation ¶
Overview ¶
Package storetesting defines helpers to test stores.
Index ¶
- type MockAdapter
- func (a *MockAdapter) AddEvidence(linkHash *types.Bytes32, evidence *cs.Evidence) error
- func (a *MockAdapter) AddStoreEventChannel(storeChan chan *store.Event)
- func (a *MockAdapter) CreateLink(link *cs.Link) (*types.Bytes32, error)
- func (a *MockAdapter) FindSegments(filter *store.SegmentFilter) (cs.SegmentSlice, error)
- func (a *MockAdapter) GetEvidences(linkHash *types.Bytes32) (*cs.Evidences, error)
- func (a *MockAdapter) GetInfo() (interface{}, error)
- func (a *MockAdapter) GetMapIDs(filter *store.MapFilter) ([]string, error)
- func (a *MockAdapter) GetSegment(linkHash *types.Bytes32) (*cs.Segment, error)
- func (a *MockAdapter) NewBatch() (store.Batch, error)
- type MockAddEvidence
- type MockAddStoreEventChannel
- type MockBatch
- func (a *MockBatch) CreateLink(link *cs.Link) (*types.Bytes32, error)
- func (a *MockBatch) FindSegments(filter *store.SegmentFilter) (cs.SegmentSlice, error)
- func (a *MockBatch) GetMapIDs(filter *store.MapFilter) ([]string, error)
- func (a *MockBatch) GetSegment(linkHash *types.Bytes32) (*cs.Segment, error)
- func (a *MockBatch) Write() error
- type MockBatchCreateLink
- type MockBatchFindSegments
- type MockBatchGetMapIDs
- type MockBatchGetSegment
- type MockBatchWrite
- type MockCreateLink
- type MockDeleteSegment
- type MockDeleteValue
- type MockFindSegments
- type MockGetEvidences
- type MockGetInfo
- type MockGetMapIDs
- type MockGetSegment
- type MockGetValue
- type MockKeyValueStore
- type MockNewBatch
- type MockSetValue
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MockAdapter ¶
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/sdk/store.Adapter.
Example ¶
This example shows how to use a mock adapter.
package main import ( "fmt" "log" "github.com/stratumn/sdk/store/storetesting" ) func main() { // 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() 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 (*MockAdapter) AddEvidence ¶ added in v0.2.0
AddEvidence implements github.com/stratumn/sdk/store.Adapter.AddEvidence.
func (*MockAdapter) AddStoreEventChannel ¶ added in v0.2.0
func (a *MockAdapter) AddStoreEventChannel(storeChan chan *store.Event)
AddStoreEventChannel implements github.com/stratumn/sdk/store.Adapter.AddStoreEventChannel.
func (*MockAdapter) CreateLink ¶ added in v0.2.0
CreateLink implements github.com/stratumn/sdk/store.Adapter.CreateLink.
func (*MockAdapter) FindSegments ¶
func (a *MockAdapter) FindSegments(filter *store.SegmentFilter) (cs.SegmentSlice, error)
FindSegments implements github.com/stratumn/sdk/store.Adapter.FindSegments.
func (*MockAdapter) GetEvidences ¶ added in v0.2.0
GetEvidences implements github.com/stratumn/sdk/store.Adapter.GetEvidences.
func (*MockAdapter) GetInfo ¶
func (a *MockAdapter) GetInfo() (interface{}, error)
GetInfo implements github.com/stratumn/sdk/store.Adapter.GetInfo.
func (*MockAdapter) GetMapIDs ¶
func (a *MockAdapter) GetMapIDs(filter *store.MapFilter) ([]string, error)
GetMapIDs implements github.com/stratumn/sdk/store.Adapter.GetMapIDs.
func (*MockAdapter) GetSegment ¶
GetSegment implements github.com/stratumn/sdk/store.Adapter.GetSegment.
type MockAddEvidence ¶ added in v0.2.0
type MockAddEvidence struct { // The number of times the function was called. CalledCount int // The evidence that was passed to each call. CalledWith []*cs.Evidence // The last evidence that was passed. LastCalledWith *cs.Evidence // An optional implementation of the function. Fn func(linkHash *types.Bytes32, evidence *cs.Evidence) error }
MockAddEvidence mocks the AddEvidence function.
type MockAddStoreEventChannel ¶ added in v0.2.0
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 ¶
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/sdk/store.Batch
func (*MockBatch) CreateLink ¶ added in v0.2.0
CreateLink implements github.com/stratumn/sdk/store.Batch.CreateLink.
func (*MockBatch) FindSegments ¶
func (a *MockBatch) FindSegments(filter *store.SegmentFilter) (cs.SegmentSlice, error)
FindSegments delegates the call to a underlying store
func (*MockBatch) GetSegment ¶
GetSegment delegates the call to a underlying store
type MockBatchCreateLink ¶ added in v0.2.0
type MockBatchCreateLink struct { // The number of times the function was called. CalledCount int // The link that was passed to each call. CalledWith []*cs.Link // The last link that was passed. LastCalledWith *cs.Link // An optional implementation of the function. Fn func(*cs.Link) (*types.Bytes32, error) }
MockBatchCreateLink mocks the CreateLink function.
type MockBatchFindSegments ¶
type MockBatchFindSegments struct { // The number of times the function was called. CalledCount int // An optional implementation of the function. Fn func(filter *store.SegmentFilter) (cs.SegmentSlice, error) }
MockBatchFindSegments mocks the FindSegments function.
type MockBatchGetMapIDs ¶
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 ¶
type MockBatchGetSegment struct { // The number of times the function was called. CalledCount int // An optional implementation of the function. Fn func(linkHash *types.Bytes32) (*cs.Segment, error) }
MockBatchGetSegment mocks the GetSegment function.
type MockBatchWrite ¶
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 ¶ added in v0.2.0
type MockCreateLink struct { // The number of times the function was called. CalledCount int // The link that was passed to each call. CalledWith []*cs.Link // The last link that was passed. LastCalledWith *cs.Link // An optional implementation of the function. Fn func(*cs.Link) (*types.Bytes32, error) }
MockCreateLink mocks the CreateLink function.
type MockDeleteSegment ¶
type MockDeleteSegment struct { // The number of times the function was called. CalledCount int // The link hash that was passed to each call. CalledWith []*types.Bytes32 // The last link hash that was passed. LastCalledWith *types.Bytes32 // An optional implementation of the function. Fn func(*types.Bytes32) (*cs.Segment, error) }
MockDeleteSegment mocks the DeleteSegment function.
type MockDeleteValue ¶
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 ¶
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) (cs.SegmentSlice, error) }
MockFindSegments mocks the FindSegments function.
type MockGetEvidences ¶ added in v0.2.0
type MockGetEvidences struct { // The number of times the function was called. CalledCount int // The link hash that was passed to each call. CalledWith []*types.Bytes32 // The last link hash that was passed. LastCalledWith *types.Bytes32 // An optional implementation of the function. Fn func(*types.Bytes32) (*cs.Evidences, error) }
MockGetEvidences mocks the GetEvidences function.
type MockGetInfo ¶
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 ¶
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 ¶
type MockGetSegment struct { // The number of times the function was called. CalledCount int // The link hash that was passed to each call. CalledWith []*types.Bytes32 // The last link hash that was passed. LastCalledWith *types.Bytes32 // An optional implementation of the function. Fn func(*types.Bytes32) (*cs.Segment, error) }
MockGetSegment mocks the GetSegment function.
type MockGetValue ¶
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 ¶ added in v0.2.0
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/sdk/store.KeyValueStore.
func (*MockKeyValueStore) DeleteValue ¶ added in v0.2.0
func (a *MockKeyValueStore) DeleteValue(key []byte) ([]byte, error)
DeleteValue implements github.com/stratumn/sdk/store.KeyValueStore.DeleteValue.
func (*MockKeyValueStore) GetValue ¶ added in v0.2.0
func (a *MockKeyValueStore) GetValue(key []byte) ([]byte, error)
GetValue implements github.com/stratumn/sdk/store.KeyValueStore.GetValue.
func (*MockKeyValueStore) SetValue ¶ added in v0.2.0
func (a *MockKeyValueStore) SetValue(key, value []byte) error
SetValue implements github.com/stratumn/sdk/store.KeyValueStore.SetValue.
type MockNewBatch ¶
type MockNewBatch struct { // The number of times the function was called. CalledCount int // An optional implementation of the function. Fn func() store.Batch }
MockNewBatch mocks the NewBatch function.
type MockSetValue ¶ added in v0.2.0
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.