uber-go / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
1.81k stars 103 forks source link

mock file not valid for generic interfaces #100

Open ehsandavari opened 9 months ago

ehsandavari commented 9 months ago

in generic use pkg path in line of code like

  import (
      context "context"
      gomock "go.uber.org/mock/gomock"
      gorm "gorm.io/gorm"
      reflect "reflect"
      entity "wallet-core/domain/entity"
      genericRepository "wallet-core/pkg/genericRepository"
  )

  func (m *MockIBaseWalletTemplateRepository) Paginate(arg0 context.Context, arg1 *genericRepository.PaginateQuery) (genericRepository.IPaginateResult[wallet-core/domain/entity.BaseWalletTemplate], error) {
      m.ctrl.T.Helper()
      ret := m.ctrl.Call(m, "Paginate", arg0, arg1)
      ret0, _ := ret[0].(genericRepository.IPaginateResult[wallet-core/domain/entity.BaseWalletTemplate])
      ret1, _ := ret[1].(error)
      return ret0, ret1
  }

bug is : wallet-core/domain/entity.BaseWalletTemplate in return of paginate func mock

I fix bug with use this

  parts := strings.Split(t, "/")
  t = parts[len(parts)-1]

in my local clone project in path mockgen/mockgen.go in top of line 588 and test code with unit tests

r-hang commented 8 months ago

I believe this is a duplicate of https://github.com/uber-go/mock/issues/97

ehsandavari commented 8 months ago

this bug fixed in #98 When will you merge this branch?

pckhoi commented 8 months ago

In the mean time, running mockgen in source mode is working pretty well for me.

bcho commented 8 months ago

I don't have time to continue my fix yet. Using source mode can help work around the issue since it runs on AST level.