mockery icon indicating copy to clipboard operation
mockery copied to clipboard

Mockery v3 Generates invalid code for private types

Open sonalys opened this issue 7 months ago • 2 comments

Description

I have a package with a private interface and types My configuration is set to generate the mocks on a different package name Mockery will generate the mock for the private interface and reference a private type, which is invalid

Expected behavior

Either:

  • Configurable option to ignore private interfaces / types
  • Mockery detects mocks are generated on a different package and ignores private interfaces / types

Mockery version

v3

Installation Mechanism

  • [x] go get
  • [] Pre-built release
  • [] homebrew
  • [] Other: [please describe]

sonalys avatar Jul 22 '25 08:07 sonalys

You can fix this by just excluding such interfaces that you know of using exclude-interface-regex. I know that's not ideal, but it would work. Your idea of having mockery detect such invalid cases is a good one, I'd be interested to hear more proposals on what this would look like in a concrete sense.

LandonTClipp avatar Jul 28 '25 04:07 LandonTClipp

@LandonTClipp I pushed a draft. I'm not happy with some parts, like built-in detection, but it solves the issue for me.

It's not ready to be merged, I'm just showing you the problem.

If you want, we can iterate over it.

sonalys avatar Jul 29 '25 20:07 sonalys