storetesting

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2017 License: Apache-2.0 Imports: 3 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 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

func (a *MockAdapter) DeleteSegment(linkHash *types.Bytes32) (*cs.Segment, error)

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

func (a *MockAdapter) GetSegment(linkHash *types.Bytes32) (*cs.Segment, error)

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

func (a *MockBatch) DeleteSegment(linkHash *types.Bytes32) (*cs.Segment, error)

DeleteSegment implements github.com/stratumn/sdk/store.Batch.DeleteSegment.

func (*MockBatch) DeleteValue

func (a *MockBatch) DeleteValue(key []byte) ([]byte, error)

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

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

GetMapIDs delegates the call to a underlying store

func (*MockBatch) GetSegment

func (a *MockBatch) GetSegment(linkHash *types.Bytes32) (*cs.Segment, error)

GetSegment delegates the call to a underlying store

func (*MockBatch) GetValue

func (a *MockBatch) GetValue(key []byte) ([]byte, error)

GetValue delegates the call to a underlying store

func (*MockBatch) SaveSegment

func (a *MockBatch) SaveSegment(segment *cs.Segment) error

SaveSegment implements github.com/stratumn/sdk/store.Batch.SaveSegment.

func (*MockBatch) SaveValue

func (a *MockBatch) SaveValue(key, value []byte) error

SaveValue implements github.com/stratumn/sdk/store.Batch.SaveValue.

func (*MockBatch) Write

func (a *MockBatch) Write() error

Write implements github.com/stratumn/sdk/store.Batch.Write.

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.

Jump to

Keyboard shortcuts

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