Documentation
¶
Overview ¶
Package storetesting defines helpers to test stores.
Index ¶
- type MockAdapter
- func (a *MockAdapter) AddEvidence(ctx context.Context, linkHash chainscript.LinkHash, ...) error
- func (a *MockAdapter) AddStoreEventChannel(storeChan chan *store.Event)
- func (a *MockAdapter) CreateLink(ctx context.Context, link *chainscript.Link) (chainscript.LinkHash, error)
- func (a *MockAdapter) FindSegments(ctx context.Context, filter *store.SegmentFilter) (*types.PaginatedSegments, error)
- func (a *MockAdapter) GetEvidences(ctx context.Context, linkHash chainscript.LinkHash) (types.EvidenceSlice, error)
- func (a *MockAdapter) GetInfo(ctx context.Context) (interface{}, error)
- func (a *MockAdapter) GetMapIDs(ctx context.Context, filter *store.MapFilter) ([]string, error)
- func (a *MockAdapter) GetSegment(ctx context.Context, linkHash chainscript.LinkHash) (*chainscript.Segment, error)
- func (a *MockAdapter) NewBatch(ctx context.Context) (store.Batch, error)
- type MockAddEvidence
- type MockAddStoreEventChannel
- type MockBatch
- func (a *MockBatch) CreateLink(ctx context.Context, link *chainscript.Link) (chainscript.LinkHash, error)
- func (a *MockBatch) FindSegments(ctx context.Context, filter *store.SegmentFilter) (*types.PaginatedSegments, error)
- func (a *MockBatch) GetMapIDs(ctx context.Context, filter *store.MapFilter) ([]string, error)
- func (a *MockBatch) GetSegment(ctx context.Context, linkHash chainscript.LinkHash) (*chainscript.Segment, error)
- func (a *MockBatch) Write(ctx context.Context) error
- type MockBatchCreateLink
- type MockBatchFindSegments
- type MockBatchGetMapIDs
- type MockBatchGetSegment
- type MockBatchWrite
- type MockCreateLink
- 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/go-core/store.Adapter.
Example ¶
This example shows how to use a mock adapter.
package main
import (
"context"
"fmt"
"log"
"github.com/stratumn/go-core/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(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 (*MockAdapter) AddEvidence ¶ added in v0.2.0
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 (*MockAdapter) AddStoreEventChannel ¶ added in v0.2.0
func (a *MockAdapter) AddStoreEventChannel(storeChan chan *store.Event)
AddStoreEventChannel implements github.com/stratumn/go-core/store.Adapter.AddStoreEventChannel.
func (*MockAdapter) CreateLink ¶ added in v0.2.0
func (a *MockAdapter) CreateLink(ctx context.Context, link *chainscript.Link) (chainscript.LinkHash, error)
CreateLink implements github.com/stratumn/go-core/store.Adapter.CreateLink.
func (*MockAdapter) FindSegments ¶
func (a *MockAdapter) FindSegments(ctx context.Context, filter *store.SegmentFilter) (*types.PaginatedSegments, error)
FindSegments implements github.com/stratumn/go-core/store.Adapter.FindSegments.
func (*MockAdapter) GetEvidences ¶ added in v0.2.0
func (a *MockAdapter) GetEvidences(ctx context.Context, linkHash chainscript.LinkHash) (types.EvidenceSlice, error)
GetEvidences implements github.com/stratumn/go-core/store.Adapter.GetEvidences.
func (*MockAdapter) GetInfo ¶
func (a *MockAdapter) GetInfo(ctx context.Context) (interface{}, error)
GetInfo implements github.com/stratumn/go-core/store.Adapter.GetInfo.
func (*MockAdapter) GetMapIDs ¶
GetMapIDs implements github.com/stratumn/go-core/store.Adapter.GetMapIDs.
func (*MockAdapter) GetSegment ¶
func (a *MockAdapter) GetSegment(ctx context.Context, linkHash chainscript.LinkHash) (*chainscript.Segment, error)
GetSegment implements github.com/stratumn/go-core/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 []*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 ¶ 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/go-core/store.Batch
func (*MockBatch) CreateLink ¶ added in v0.2.0
func (a *MockBatch) CreateLink(ctx context.Context, link *chainscript.Link) (chainscript.LinkHash, error)
CreateLink implements github.com/stratumn/go-core/store.Batch.CreateLink.
func (*MockBatch) FindSegments ¶
func (a *MockBatch) FindSegments(ctx context.Context, filter *store.SegmentFilter) (*types.PaginatedSegments, error)
FindSegments delegates the call to a underlying store
func (*MockBatch) GetSegment ¶
func (a *MockBatch) GetSegment(ctx context.Context, linkHash chainscript.LinkHash) (*chainscript.Segment, error)
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 []*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 ¶
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 ¶
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 chainscript.LinkHash) (*chainscript.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 []*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 ¶
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) (*types.PaginatedSegments, 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 []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 ¶
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 []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 ¶
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/go-core/store.KeyValueStore.
func (*MockKeyValueStore) DeleteValue ¶ added in v0.2.0
DeleteValue implements github.com/stratumn/go-core/store.KeyValueStore.DeleteValue.
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, error)
}
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.