Documentation
¶
Overview ¶
Package mock contains simple utilities for testing with mocks.
A Mock can be installed and restored. This package contains types and functions for creating and using such mocks.
The main idea is that instead of this
m1 := &mockWhatever{
Foo: "bar",
}
m1.Install()
defer m1.Restore()
m2 := &mockAnother{
Baz: "Quux",
}
m2.Install()
defer m2.Restore()
we can do this
mocks := mock.Group{
&mockWhatever{
Foo: "bar",
},
&mockAnother{
Baz: "Quux",
},
}
mocks.Install()
defer mocks.Restore()
or
func TestSomething(t *testing.T) {
mock.UntilCleanup(t,
&mockWhatever{
Foo: "bar",
},
&mockAnother{
Baz: "Quux",
},
)
...
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Restore ¶
func Restore(ms ...Mock)
Restore restores each of the given Mocks. They are restored in reverse order, in case they have ordering dependencies.
func UntilCleanup ¶
func UntilCleanup(t Cleanupper, ms ...Mock)
UntilCleanup installs the given mocks and tells t to restore them on Cleanup. Usually, t is a *testing.T.
Types ¶
type Cleanupper ¶
type Cleanupper interface {
Cleanup(func())
}
A Cleanupper can be asked to call a cleanup function. The most common Cleanupper is *testing.T.
Click to show internal directories.
Click to hide internal directories.