Using go mock for mocking interfaces

Hello

I am using gomock version 1.6.0. Here is how i am using it.

//go:generate mockgen -destination=./mytype_mock_test.go -package=mytype_test -build_flags=-mod=mod {{module name}}/{{path_to_my_type_intertface}} MyType
type MyType interface {
	Ge(ctx context.Context, id int64) (*Type, error)
	Updater(ctx context.Context, type *Type) error
	Create(ctx context.Context, type *Type) error
}

This is the script that I use for generating my mocks.

#!/bin/bash

go install github.com/golang/mock/mockgen@v1.6.0

go generate ./...

The mocks are generated successfully but when I run my tests and I am running them with Bazel (monorepo with microsevices) and I am getting this error.

{{path_to_my_type_intertface}}/rmytype_mock_test.go:40:9: m.ctrl.T undefined (type *gomock.Controller has no field or method T)
43
{{path_to_my_type_intertface}}/mytype_mock_test.go:48:15: mr.mock.ctrl.T undefined (type *gomock.Controller has no field or method T)

Do you know why it might be because i can see that there is type T in gomock.Controller?

Thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.