mock icon indicating copy to clipboard operation
mock copied to clipboard

Should not resolve type alias when generate mock files

Open lance6716 opened this issue 1 year ago • 2 comments

Actual behavior A clear and concise description of what the bug is.

we have an interface that uses "github.com/tikv/client-go/v2/tikv".Codec. And that type is defined as

under "github.com/tikv/client-go/v2/tikv":

import "github.com/tikv/client-go/v2/internal/apicodec"
...
type Codec = apicodec.Codec

In the generated mock files, it directly imports "github.com/tikv/client-go/v2/internal/apicodec" which is not allowed for the non-internal usage.

Expected behavior A clear and concise description of what you expected to happen.

It should import "github.com/tikv/client-go/v2/tikv" instead

To Reproduce Steps to reproduce the behavior

  1. ...
  2. ...

Additional Information

  • gomock mode (reflect or source): default value
  • gomock version or git ref: v0.5.0
  • golang version: 1.23

Triage Notes for the Maintainers

lance6716 avatar Oct 21 '24 05:10 lance6716

Hey @lance6716 - how is the Codec type being used in terms of the interface you're trying to mock? Can you show us:

  • The definition of the interface you're trying to mock
  • The mockgen command you're running

Thanks

JacobOaks avatar Oct 21 '24 17:10 JacobOaks

@JacobOaks I pushed example code here https://github.com/lance6716/mock/tree/show216/example

The command is mockgen -package mock . Foo > ./mock/gen.go

And can you take a look at https://github.com/uber-go/mock/pull/171 ? Thanks.

lance6716 avatar Oct 22 '24 00:10 lance6716