go-core: github.com/stratumn/go-core/store/storetesting Index | Examples | Files

package storetesting

import "github.com/stratumn/go-core/store/storetesting"

Package storetesting defines helpers to test stores.

Index

Examples

Package Files

mock_batch.go mockadapter.go storetesting.go

type MockAdapter Uses

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 (*MockAdapter) AddEvidence Uses

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 Uses

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 (*MockAdapter) FindSegments Uses

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 Uses

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 Uses

func (a *MockAdapter) GetInfo(ctx context.Context) (interface{}, error)

GetInfo implements github.com/stratumn/go-core/store.Adapter.GetInfo.

func (*MockAdapter) GetMapIDs Uses

func (a *MockAdapter) GetMapIDs(ctx context.Context, filter *store.MapFilter) ([]string, error)

GetMapIDs implements github.com/stratumn/go-core/store.Adapter.GetMapIDs.

func (*MockAdapter) GetSegment Uses

func (a *MockAdapter) GetSegment(ctx context.Context, linkHash chainscript.LinkHash) (*chainscript.Segment, error)

GetSegment implements github.com/stratumn/go-core/store.Adapter.GetSegment.

func (*MockAdapter) NewBatch Uses

func (a *MockAdapter) NewBatch(ctx context.Context) (store.Batch, error)

NewBatch implements github.com/stratumn/go-core/store.Adapter.NewBatch.

type MockAddEvidence Uses

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 Uses

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 Uses

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 (*MockBatch) FindSegments Uses

func (a *MockBatch) FindSegments(ctx context.Context, filter *store.SegmentFilter) (*types.PaginatedSegments, error)

FindSegments delegates the call to a underlying store

func (*MockBatch) GetMapIDs Uses

func (a *MockBatch) GetMapIDs(ctx context.Context, filter *store.MapFilter) ([]string, error)

GetMapIDs delegates the call to a underlying store

func (*MockBatch) GetSegment Uses

func (a *MockBatch) GetSegment(ctx context.Context, linkHash chainscript.LinkHash) (*chainscript.Segment, error)

GetSegment delegates the call to a underlying store

func (*MockBatch) Write Uses

func (a *MockBatch) Write(ctx context.Context) error

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (a *MockKeyValueStore) DeleteValue(ctx context.Context, key []byte) ([]byte, error)

DeleteValue implements github.com/stratumn/go-core/store.KeyValueStore.DeleteValue.

func (*MockKeyValueStore) GetValue Uses

func (a *MockKeyValueStore) GetValue(ctx context.Context, key []byte) ([]byte, error)

GetValue implements github.com/stratumn/go-core/store.KeyValueStore.GetValue.

func (*MockKeyValueStore) SetValue Uses

func (a *MockKeyValueStore) SetValue(ctx context.Context, key, value []byte) error

SetValue implements github.com/stratumn/go-core/store.KeyValueStore.SetValue.

type MockNewBatch Uses

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 Uses

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.