vektra / mockery

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

Logging warning when mock config is orphaned #764

Open bentcoder opened 6 months ago

bentcoder commented 6 months ago

Mockery Version

v2.42.0

Golang Version

go1.22.0 amd64

Installation Method

Steps to Reproduce

  1. Create an interface
  2. Add it to config file
  3. Run mockery to create mock
  4. Manually delete or comment out interface
  5. Rerun mockery command

Expected Behavior

Since interface doesn't exists anymore, I would have expected mockery command to error or something because there is a misleading/redundant reference in config.

Actual Behavior

Physical mock file is still in the codebase but unfortunately it is redundant because there is no interface for it anymore.

quiet: false
dir: "{{.InterfaceDir}}/mocks"
mockname: "{{.InterfaceName|camelcase}}"
filename: "{{.InterfaceName|snakecase}}.go"
outpkg: mocks

packages:
  github.com/myself/app/src/service:
    interfaces:
      MyInterface:
LandonTClipp commented 6 months ago

This should be very easy to add. Initially, we should only add a warning log to retain backwards compatibility. I'm approving this feature request to add a log. I do not want mockery to mutate the config, or delete old mock files, however. Removal of user's mocks should be the user's responsibility, as there are too many edge cases for mockery to handle it properly.