mock

module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2020 License: Apache-2.0

README

gomock

GoMock is a mocking framework for the Go programming language. It integrates well with Go's built-in testing package, but can be used in other contexts too. This is a fork that allows the gomock library to print its output as a diff. This is especially useful when the mock receives a map or a slice and errors. Instead of showing a gigantic blob, wrapping in the terminal several times, you get just the parts of the argument that are different.

Installation

Install and gomock/mockgen as normal, then:

mkdir vendor
git clone git@github.com:fishybell/mock vendor/mock
echo "replace github.com/fishybell/mock => ./vendor/mock" >> go.mod

This is necessary as the mock package uses types rather than interfaces.

If you are using a Matcher, extending the Matcher interface to be a DiffableMatcher interface is required for fancier output:

// A DiffableMatcher is a representation of a class of values.
// It is used to represent the valid or expected arguments to a mocked method.
// The only difference is the Value() function to allow for full matching
type DiffableMatcher interface {
	// Matches returns whether x is a match.
	Matches(x interface{}) bool

	// String describes what the matcher matches.
	String() string

	// Value returns the original value, for use in Diff output
	Value() interface{}
}

This is exactly the same as the Matcher interface, with the addition of the Value() function. You can continue to use the Matcher interface if you wish.

Directories

Path Synopsis
Package gomock is a mock framework for Go.
Package gomock is a mock framework for Go.
internal/mock_gomock
Package mock_gomock is a generated GoMock package.
Package mock_gomock is a generated GoMock package.
MockGen generates mock implementations of Go interfaces.
MockGen generates mock implementations of Go interfaces.
internal/tests/aux_imports_embedded_interface
Package bugreport is a generated GoMock package.
Package bugreport is a generated GoMock package.
internal/tests/copyright_file
Package empty_interface is a generated GoMock package.
Package empty_interface is a generated GoMock package.
internal/tests/dot_imports
Package dot_imports is a generated GoMock package.
Package dot_imports is a generated GoMock package.
internal/tests/empty_interface
Package empty_interface is a generated GoMock package.
Package empty_interface is a generated GoMock package.
internal/tests/generated_identifier_conflict
Package bugreport is a generated GoMock package.
Package bugreport is a generated GoMock package.
internal/tests/import_source
Package mock_source is a generated GoMock package.
Package mock_source is a generated GoMock package.
internal/tests/import_source/definition
Package source is a generated GoMock package.
Package source is a generated GoMock package.
internal/tests/internal_pkg/subdir/internal/pkg/reflect_output
Package mock_pkg is a generated GoMock package.
Package mock_pkg is a generated GoMock package.
internal/tests/internal_pkg/subdir/internal/pkg/source_output
Package mock_pkg is a generated GoMock package.
Package mock_pkg is a generated GoMock package.
internal/tests/unexported_method
Package bugreport is a generated GoMock package.
Package bugreport is a generated GoMock package.
internal/tests/vendor_dep
Package vendor_dep is a generated GoMock package.
Package vendor_dep is a generated GoMock package.
internal/tests/vendor_dep/source_mock_package
Package mock_vendor_dep is a generated GoMock package.
Package mock_vendor_dep is a generated GoMock package.
internal/tests/vendor_pkg
Package vendor_pkg is a generated GoMock package.
Package vendor_pkg is a generated GoMock package.
model
Package model contains the data model necessary for generating mock implementations.
Package model contains the data model necessary for generating mock implementations.
An example package with an interface.
An example package with an interface.
concurrent
Package concurrent demonstrates how to use gomock with goroutines.
Package concurrent demonstrates how to use gomock with goroutines.
concurrent/mock
Package mock_concurrent is a generated GoMock package.
Package mock_concurrent is a generated GoMock package.
mock_user
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