fossilizertesting

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2018 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package fossilizertesting defines helpers to test fossilizers.

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 AddFossilizerEventChan function.
	MockAddFossilizerEventChan MockAddFossilizerEventChan

	// The mock for the Fossilize function.
	MockFossilize MockFossilize
}

MockAdapter is used to mock a fossilizer.

It implements github.com/stratumn/sdk/fossilizer.Adapter.

Example

This example shows how to use a mock adapter.

package main

import (
	"fmt"
	"log"

	"github.com/stratumn/sdk/fossilizer/fossilizertesting"
)

func main() {
	// Create a mock.
	m := fossilizertesting.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) AddFossilizerEventChan added in v0.2.0

func (a *MockAdapter) AddFossilizerEventChan(eventChan chan *fossilizer.Event)

AddFossilizerEventChan implements github.com/stratumn/sdk/fossilizer.Adapter.AddFossilizerEventChan.

func (*MockAdapter) Fossilize

func (a *MockAdapter) Fossilize(data []byte, meta []byte) error

Fossilize implements github.com/stratumn/sdk/fossilizer.Adapter.Fossilize.

func (*MockAdapter) GetInfo

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

GetInfo implements github.com/stratumn/sdk/fossilizer.Adapter.GetInfo.

type MockAddFossilizerEventChan added in v0.2.0

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

	// The channel that was passed to each call.
	CalledWith []chan *fossilizer.Event

	// The last channel that was passed.
	LastCalledWith chan *fossilizer.Event

	// An optional implementation of the function.
	Fn func(chan *fossilizer.Event)
}

MockAddFossilizerEventChan mocks the AddFossilizerEventChan function.

type MockFossilize

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

	// The data that was passed to each call.
	CalledWithData [][]byte

	// The meta that was passed to each call.
	CalledWithMeta [][]byte

	// The last data that was passed.
	LastCalledWithData []byte

	// The last meta that was passed.
	LastCalledWithMeta []byte

	// An optional implementation of the function.
	Fn func([]byte, []byte) error
}

MockFossilize mocks the Fossilize 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.

Jump to

Keyboard shortcuts

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