Documentation ¶
Overview ¶
Package storetesting defines helpers to test stores.
Index ¶
- type MockAdapter
- func (a *MockAdapter) AddDidSaveChannel(saveChan chan *cs.Segment)
- func (a *MockAdapter) DeleteSegment(linkHash *types.Bytes32) (*cs.Segment, error)
- func (a *MockAdapter) DeleteValue(key []byte) ([]byte, error)
- func (a *MockAdapter) FindSegments(filter *store.SegmentFilter) (cs.SegmentSlice, 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) GetValue(key []byte) ([]byte, error)
- func (a *MockAdapter) NewBatch() (store.Batch, error)
- func (a *MockAdapter) SaveSegment(segment *cs.Segment) error
- func (a *MockAdapter) SaveValue(key, value []byte) error
- type MockAddDidSaveChannel
- type MockBatch
- func (a *MockBatch) DeleteSegment(linkHash *types.Bytes32) (*cs.Segment, error)
- func (a *MockBatch) DeleteValue(key []byte) ([]byte, 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) GetValue(key []byte) ([]byte, error)
- func (a *MockBatch) SaveSegment(segment *cs.Segment) error
- func (a *MockBatch) SaveValue(key, value []byte) error
- func (a *MockBatch) Write() error
- type MockBatchDeleteSegment
- type MockBatchDeleteValue
- type MockBatchFindSegments
- type MockBatchGetMapIDs
- type MockBatchGetSegment
- type MockBatchGetValue
- type MockBatchSaveSegment
- type MockBatchSaveValue
- type MockBatchWrite
- type MockDeleteSegment
- type MockDeleteValue
- type MockFindSegments
- type MockGetInfo
- type MockGetMapIDs
- type MockGetSegment
- type MockGetValue
- type MockNewBatch
- type MockSaveSegment
- type MockSaveValue
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 AddDidSaveChannel function. MockAddDidSaveChannel MockAddDidSaveChannel // The mock for the SaveSegment function. MockSaveSegment MockSaveSegment // The mock for the SaveValue function. MockSaveValue MockSaveValue // The mock for the GetSegment function. MockGetSegment MockGetSegment // The mock for the GetValue function. MockGetValue MockGetValue // The mock for the DeleteSegment function. MockDeleteSegment MockDeleteSegment // The mock for the DeleteValue function. MockDeleteValue MockDeleteValue // 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) AddDidSaveChannel ¶
func (a *MockAdapter) AddDidSaveChannel(saveChan chan *cs.Segment)
AddDidSaveChannel implements github.com/stratumn/sdk/store.Adapter.AddDidSaveChannel.
func (*MockAdapter) DeleteSegment ¶
DeleteSegment implements github.com/stratumn/sdk/store.Adapter.DeleteSegment.
func (*MockAdapter) DeleteValue ¶
func (a *MockAdapter) DeleteValue(key []byte) ([]byte, error)
DeleteValue implements github.com/stratumn/sdk/store.Adapter.DeleteValue.
func (*MockAdapter) FindSegments ¶
func (a *MockAdapter) FindSegments(filter *store.SegmentFilter) (cs.SegmentSlice, error)
FindSegments implements github.com/stratumn/sdk/store.Adapter.FindSegments.
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.
func (*MockAdapter) GetValue ¶
func (a *MockAdapter) GetValue(key []byte) ([]byte, error)
GetValue implements github.com/stratumn/sdk/store.Adapter.GetValue.
func (*MockAdapter) NewBatch ¶
func (a *MockAdapter) NewBatch() (store.Batch, error)
NewBatch implements github.com/stratumn/sdk/store.Adapter.NewBatch.
func (*MockAdapter) SaveSegment ¶
func (a *MockAdapter) SaveSegment(segment *cs.Segment) error
SaveSegment implements github.com/stratumn/sdk/store.Adapter.SaveSegment.
func (*MockAdapter) SaveValue ¶
func (a *MockAdapter) SaveValue(key, value []byte) error
SaveValue implements github.com/stratumn/sdk/store.Adapter.SaveValue.
type MockAddDidSaveChannel ¶
type MockAddDidSaveChannel struct { // The number of times the function was called. CalledCount int // The segment that was passed to each call. CalledWith []chan *cs.Segment // The last segment that was passed. LastCalledWith chan *cs.Segment // An optional implementation of the function. Fn func(chan *cs.Segment) }
MockAddDidSaveChannel mocks the SaveSegment function.
type MockBatch ¶
type MockBatch struct { // The mock for the SaveSegment function. MockSaveSegment MockBatchSaveSegment // The mock for the SaveValue function. MockSaveValue MockBatchSaveValue // The mock for the DeleteSegment function. MockDeleteSegment MockBatchDeleteSegment // The mock for the DeleteValue function. MockDeleteValue MockBatchDeleteValue // 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 // The mock for the GetValue function. MockGetValue MockBatchGetValue }
MockBatch is used to mock a batch.
It implements github.com/stratumn/sdk/store.Batch.
func (*MockBatch) DeleteSegment ¶
DeleteSegment implements github.com/stratumn/sdk/store.Batch.DeleteSegment.
func (*MockBatch) DeleteValue ¶
DeleteValue implements github.com/stratumn/sdk/store.Batch.DeleteValue.
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
func (*MockBatch) SaveSegment ¶
SaveSegment implements github.com/stratumn/sdk/store.Batch.SaveSegment.
type MockBatchDeleteSegment ¶
type MockBatchDeleteSegment 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) }
MockBatchDeleteSegment mocks the DeleteSegment function.
type MockBatchDeleteValue ¶
type MockBatchDeleteValue 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) }
MockBatchDeleteValue mocks the DeleteValue 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 MockBatchGetValue ¶
type MockBatchGetValue struct { // The number of times the function was called. CalledCount int // An optional implementation of the function. Fn func(key []byte) ([]byte, error) }
MockBatchGetValue mocks the GetValue function.
type MockBatchSaveSegment ¶
type MockBatchSaveSegment struct { // The number of times the function was called. CalledCount int // The segment that was passed to each call. CalledWith []*cs.Segment // The last segment that was passed. LastCalledWith *cs.Segment // An optional implementation of the function. Fn func(*cs.Segment) error }
MockBatchSaveSegment mocks the SaveSegment function.
type MockBatchSaveValue ¶
type MockBatchSaveValue 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 }
MockBatchSaveValue mocks the SaveValue 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 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 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 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 MockSaveSegment ¶
type MockSaveSegment struct { // The number of times the function was called. CalledCount int // The segment that was passed to each call. CalledWith []*cs.Segment // The last segment that was passed. LastCalledWith *cs.Segment // An optional implementation of the function. Fn func(*cs.Segment) error }
MockSaveSegment mocks the SaveSegment function.
type MockSaveValue ¶
type MockSaveValue 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 }
MockSaveValue mocks the SaveValue function.