vektra / mockery

A mock code autogenerator for Go
https://vektra.github.io/mockery/
BSD 3-Clause "New" or "Revised" License
5.96k stars 402 forks source link

mock generation for non-relative-to-interface dirs #802

Open tobby-s opened 1 month ago

tobby-s commented 1 month ago

Description

when the dir config is specified as not relative to the package (doesn't use {{.InterfaceDir}} template), the generation is relative to the current working directory rather than the project root (or wherever .mockery.yaml is specified).

Mockery Version

2.42.1

Go Version

1.22.3

NOTE: Please upgrade to the latest golang version before submitting tickets!

Installation Method

Steps to Reproduce

  1. write an interface in a package (or set .mockery.yaml to mock an interface from an external go module, which is the use-case i'm encountering this issue), have /mocks directory exist in project root
  2. set dir to mocks in .mockery.yaml, e.g.:
    with-expecter: true
    dir: "mocks"
    outpkg: "mocks"
    mockname: "{{.InterfaceName}}"
    filename: "{{.InterfaceName}}.go"
    packages:
    context:
    interfaces:
      Context:
  3. run mockery in project root then cd mocks and run it again

Expected Behavior

the second mockery shouldn't add any new files since config file was not changed between the two runs

Actual Behavior

new mocks are created in mocks/mocks

Proposal

add a new template that indicates the .mockery.yaml location, e.g. {{.ConfigDir}}

LandonTClipp commented 1 month ago

add a new template that indicates the .mockery.yaml location, e.g. {{.ConfigDir}}

This is a great idea and should be super easy to do. I approve of doing this, but I'm not sure when I'll have the time to get to it. Maybe in the next week or two unless anyone else wants to take it.

tobby-s commented 3 weeks ago

https://github.com/vektra/mockery/pull/807

do let me know of any other documenatation / tests etc i need to add.