storetesting

package
v0.0.2-dev Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2016 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 SaveSegment function.
	MockSaveSegment MockSaveSegment

	// The mock for the GetSegment function.
	MockGetSegment MockGetSegment

	// The mock for the DeleteSegment function.
	MockDeleteSegment MockDeleteSegment

	// The mock for the FindSegments function.
	MockFindSegments MockFindSegments

	// The mock for the GetMapIDs function.
	MockGetMapIDs MockGetMapIDs
}

MockAdapter is used to mock a store.

It implements github.com/stratumn/go/store.Adapter.

Example

This example shows how to use a mock adapter.

package main

import (
	"fmt"
	"log"

	"github.com/stratumn/go/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) DeleteSegment

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

DeleteSegment implements github.com/stratumn/go/store.Adapter.DeleteSegment.

func (*MockAdapter) FindSegments

func (a *MockAdapter) FindSegments(filter *store.Filter) (cs.SegmentSlice, error)

FindSegments implements github.com/stratumn/go/store.Adapter.FindSegments.

func (*MockAdapter) GetInfo

func (a *MockAdapter) GetInfo() (interface{}, error)

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

func (*MockAdapter) GetMapIDs

func (a *MockAdapter) GetMapIDs(pagination *store.Pagination) ([]string, error)

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

func (*MockAdapter) GetSegment

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

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

func (*MockAdapter) SaveSegment

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

SaveSegment implements github.com/stratumn/go/store.Adapter.SaveSegment.

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 MockFindSegments

type MockFindSegments struct {
	// The number of times the function was called.
	CalledCount int

	// The filter that was passed to each call.
	CalledWith []*store.Filter

	// The last filter that was passed.
	LastCalledWith *store.Filter

	// An optional implementation of the function.
	Fn func(*store.Filter) (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.Pagination

	// The last pagination that was passed.
	LastCalledWith *store.Pagination

	// An optional implementation of the function.
	Fn func(*store.Pagination) ([]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 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.

Jump to

Keyboard shortcuts

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