storetesting

package
v0.4.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package storetesting defines helpers to test stores.

Index

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 (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

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

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

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

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

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 (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) GetMapIDs

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

GetMapIDs 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

func (*MockBatch) Write

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

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 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

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

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

func (*MockKeyValueStore) GetValue added in v0.2.0

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

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

func (*MockKeyValueStore) SetValue added in v0.2.0

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

SetValue implements github.com/stratumn/go-core/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, 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL