mock icon indicating copy to clipboard operation
mock copied to clipboard

mock file not valid for generic interfaces

Open ehsandavari opened this issue 2 years ago • 6 comments

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

ehsandavari avatar Oct 04 '23 14:10 ehsandavari

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

r-hang avatar Oct 10 '23 18:10 r-hang

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

ehsandavari avatar Oct 20 '23 11:10 ehsandavari

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

pckhoi avatar Oct 27 '23 08:10 pckhoi

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.

bcho avatar Nov 01 '23 19:11 bcho

this issue is fixed?

ehsandavari avatar Aug 31 '24 18:08 ehsandavari

i use mockery and mockery support that https://github.com/vektra/mockery

ehsandavari avatar Sep 01 '24 08:09 ehsandavari