user

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

README

This directory contains an example of a package containing a non-trivial interface that can be mocked with GoMock. The interesting files are:

  • user.go: Source code for the sample package, containing interfaces to be mocked. This file depends on the packages named imp[1-4] for various things.

  • user_test.go: A test for the sample package, in which mocks of the interfaces from user.go are used. This demonstrates how to create mock objects, set up expectations, and so on.

  • mock_user/mock_user.go: The generated mock code. See ../gomock/matchers.go for the go:generate command used to generate it.

To run the test,

go test github.com/golang/mock/sample

Documentation

Overview

An example package with an interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GrabPointer

func GrabPointer(index Index) int

func Remember

func Remember(index Index, keys []string, values []interface{})

A function that we will test that uses the above interface. It takes a list of keys and values, and puts them in the index.

Types

type Embed

type Embed interface {
	RegularMethod()
	Embedded
	imp1.ForeignEmbedded
}

An interface with an embedded interface.

type Embedded

type Embedded interface {
	EmbeddedMethod()
}

type Index

type Index interface {
	Get(key string) interface{}
	GetTwo(key1, key2 string) (v1, v2 interface{})
	Put(key string, value interface{})

	// Check that imports are handled correctly.
	Summary(buf *btz.Buffer, w io.Writer)
	Other() hash.Hash
	Templates(a t1.CSS, b t2.FuncMap)

	// A method with an anonymous argument.
	Anon(string)

	// Methods using foreign types outside the standard library.
	ForeignOne(imp1.Imp1)
	ForeignTwo(renamed2.Imp2)
	ForeignThree(Imp3)
	ForeignFour(imp_four.Imp4)

	// A method that returns a nillable type.
	NillableRet() error
	// A method that returns a non-interface type.
	ConcreteRet() chan<- bool

	// Methods with an ellipsis argument.
	Ellip(fmt string, args ...interface{})
	EllipOnly(...string)

	// A method with a pointer argument that we will set.
	Ptr(arg *int)

	// A method with a slice argument and an array return.
	Slice(a []int, b []byte) [3]int

	// A method with channel arguments.
	Chan(a chan int, b chan<- hash.Hash)

	// A method with a function argument.
	Func(f func(http.Request) (int, bool))

	// A method with a map argument.
	Map(a map[int]hash.Hash)

	// Methods with an unnamed empty struct argument.
	Struct(a struct{})          // not so likely
	StructChan(a chan struct{}) // a bit more common
}

A bizarre interface to test corner cases in mockgen. This would normally be in its own file or package, separate from the user of it (e.g. io.Reader).

Directories

Path Synopsis
Package concurrent demonstrates how to use gomock with goroutines.
Package concurrent demonstrates how to use gomock with goroutines.
mock
Package mock_concurrent is a generated GoMock package.
Package mock_concurrent is a generated GoMock package.
Package mock_sample is a generated GoMock package.
Package mock_sample is a generated GoMock package.

Jump to

Keyboard shortcuts

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