mock.go 445 B

12345678910111213141516171819202122
  1. package mock
  2. import (
  3. "gitee.com/xuyiping_admin/pkg/di"
  4. kptservicemock "kpt-tmr-group/module/backend/mock"
  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. )