fossilizertesting

package
v0.0.5-dev Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2017 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 AddResultChan function.
	MockAddResultChan MockAddResultChan

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

MockAdapter is used to mock a fossilizer.

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

Example

This example shows how to use a mock adapter.

package main

import (
	"fmt"
	"log"

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

func (a *MockAdapter) AddResultChan(resultChan chan *fossilizer.Result)

AddResultChan implements github.com/stratumn/go/fossilizer.Adapter.AddResultChan.

func (*MockAdapter) Fossilize

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

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

func (*MockAdapter) GetInfo

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

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

type MockAddResultChan

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

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

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

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

MockAddResultChan mocks the AddResultChan 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