Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit fcef047

Browse files
authored
Add ControllerOption (#24)
Originally discussed in #238. This adds a functional option parameter to NewController to allow adding future configurations to control the behavior of Controller. This will come in handy for implementing features like the one in #22.
1 parent e86b1bf commit fcef047

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

gomock/controller.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ type Controller struct {
8686
//
8787
// New in go1.14+, if you are passing a *testing.T into this function you no
8888
// longer need to call ctrl.Finish() in your test methods.
89-
func NewController(t TestReporter) *Controller {
89+
func NewController(t TestReporter, opts ...ControllerOption) *Controller {
9090
h, ok := t.(TestHelper)
9191
if !ok {
9292
h = &nopTestHelper{t}
@@ -95,6 +95,9 @@ func NewController(t TestReporter) *Controller {
9595
T: h,
9696
expectedCalls: newCallSet(),
9797
}
98+
for _, opt := range opts {
99+
opt.apply(ctrl)
100+
}
98101
if c, ok := isCleanuper(ctrl.T); ok {
99102
c.Cleanup(func() {
100103
ctrl.T.Helper()
@@ -105,6 +108,12 @@ func NewController(t TestReporter) *Controller {
105108
return ctrl
106109
}
107110

111+
// ControllerOption configures how a Controller should behave. Currently
112+
// there are no implementations of it.
113+
type ControllerOption interface {
114+
apply(*Controller)
115+
}
116+
108117
type cancelReporter struct {
109118
t TestHelper
110119
cancel func()

0 commit comments

Comments
 (0)