mock_sandbox

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

README

Mock

Install

$ go get github.com/golang/mock/gomock
$ go install github.com/golang/mock/mockgen

Usage

In the main package directory: $ mockgen -source=interface.go -destination=mock/mock.go

Testing

func foo(p2pSvc ptp.Interface) (*statechain.Diff, error) {
  // foo does stuff, here...
}

func TestFoo(t *testing.T) {
  // 1. mock the p2p service
	mockCtrl := gomock.NewController(t)
	defer mockCtrl.Finish()

  mockP2P := mock_p2p.NewMockInterface(mockCtrl)
	mockP2P.
		EXPECT().
		GetStatechainDiff(gomock.Any()).
		Return(diff, nil)

	mockP2P.
		EXPECT().
		GetStatechainBlock(gomock.Any()).
		Return(block, nil)

	mockP2P.
		EXPECT().
		GetStatechainDiff(gomock.Any()).
		Return(diff, nil)

	mockP2P.
		EXPECT().
		GetStatechainBlock(gomock.Any()).
		Return(genesisBlock, nil)

	mockP2P.
		EXPECT().
		GetStatechainDiff(gomock.Any()).
		Return(diff, nil)

	// 2. run the function
	diffs, err := foo(mockP2P)
	if err != nil {
		t.Fatal(err)
  }
    
  // etc...
} 

Documentation

Overview

Package mock_sandbox is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockInterface

type MockInterface struct {
	// contains filtered or unexported fields
}

MockInterface is a mock of Interface interface

func NewMockInterface

func NewMockInterface(ctrl *gomock.Controller) *MockInterface

NewMockInterface creates a new mock instance

func (*MockInterface) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockInterface) Play

func (m *MockInterface) Play(config *sandbox.PlayConfig) ([]byte, error)

Play mocks base method

type MockInterfaceMockRecorder

type MockInterfaceMockRecorder struct {
	// contains filtered or unexported fields
}

MockInterfaceMockRecorder is the mock recorder for MockInterface

func (*MockInterfaceMockRecorder) Play

func (mr *MockInterfaceMockRecorder) Play(config interface{}) *gomock.Call

Play indicates an expected call of Play

Jump to

Keyboard shortcuts

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