mock.go 434 B

12345678910111213141516171819202122
  1. package mock
  2. import (
  3. kptservicemock "kpt-tmr-group/module/backend/mock"
  4. "kpt-tmr-group/pkg/di"
  5. "github.com/golang/mock/gomock"
  6. )
  7. func GetMock(ctrl *gomock.Controller, f interface{}) {
  8. container, err := di.New(di.Provide(func() *gomock.Controller { return ctrl }), deps)
  9. if err != nil {
  10. panic(err)
  11. }
  12. if err = container.Invoke(f); err != nil {
  13. panic(err)
  14. }
  15. }
  16. var deps = di.Provide(
  17. kptservicemock.NewMockKptService,
  18. )