vektra / mockery

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

Generation fails when referencing module that uses the `replace` directive #815

Open jmgilman opened 2 months ago

jmgilman commented 2 months ago

Description

When referencing a Go module that is being replaced using the replace directive in the go.mod file, mockery fails to load the package.

Mockery Version

v2.45.0

Go Version

v1.23.0

Installation Method

Steps to Reproduce

Start with a go.mod that uses replace:

module github.com/my/pkg/otherpkg

require (
    github.com/my/pkg/tools v0.0.0
)

replace github.com/my/pkg/tools => ../tools

go 1.23.0

And then attempt to generate mocks for interfaces in that package:

with-expecter: true
packages:
    github.com/my/pkg/tools:
        interfaces:
            Interface1:
            Interface2:

When running mockery, it will error out saying there's no module providing github.com/my/pkg/tools. However, Go itself has no issues importing the package.

Expected Behavior

Expected mockery to behave the same way as Go.

Actual Behavior

Mockery fails with:

07 Sep 24 19:07 EDT ERR encountered error when loading package error="-: no required module provides package github.com/my/pkg/tools; to add it:\n\tgo get github.com/my/pkg/tools" dry-run=false version=v2.45.0