Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ControllerOption #24

Merged
merged 1 commit into from
Jul 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion gomock/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type Controller struct {
//
// New in go1.14+, if you are passing a *testing.T into this function you no
// longer need to call ctrl.Finish() in your test methods.
func NewController(t TestReporter) *Controller {
func NewController(t TestReporter, opts ...ControllerOption) *Controller {
h, ok := t.(TestHelper)
if !ok {
h = &nopTestHelper{t}
Expand All @@ -95,6 +95,9 @@ func NewController(t TestReporter) *Controller {
T: h,
expectedCalls: newCallSet(),
}
for _, opt := range opts {
opt.apply(ctrl)
}
if c, ok := isCleanuper(ctrl.T); ok {
c.Cleanup(func() {
ctrl.T.Helper()
Expand All @@ -105,6 +108,12 @@ func NewController(t TestReporter) *Controller {
return ctrl
}

// ControllerOption configures how a Controller should behave. Currently
// there are no implementations of it.
type ControllerOption interface {
apply(*Controller)
}

type cancelReporter struct {
t TestHelper
cancel func()
Expand Down