vektra / mockery

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

Fix replace-type for different packages from the same source #710

Closed RangelReale closed 1 year ago

RangelReale commented 1 year ago

Description

When different packages that map to the same source package and mapped with replace-type, the package of the first one are used for all other packages.

Type of change

Version of Golang used when building/testing:

How Has This Been Tested?

Checklist

RangelReale commented 1 year ago

@LandonTClipp had to add the type to the addPackageImportWithName to be able to differentiate between them, I only replace if this parameter is not nil. Also added some specifity rule to check replaces with types first.

@rkoehl05 can you see if this fixes your problem?

codecov[bot] commented 1 year ago

Codecov Report

All modified lines are covered by tests :white_check_mark:

Comparison is base (f54eea9) 74.88090% compared to head (ee33b3d) 74.91349%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #710 +/- ## =================================================== + Coverage 74.88090% 74.91349% +0.03258% =================================================== Files 9 9 Lines 2309 2312 +3 =================================================== + Hits 1729 1732 +3 Misses 442 442 Partials 138 138 ``` | [Files](https://app.codecov.io/gh/vektra/mockery/pull/710?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vektra) | Coverage Δ | | |---|---|---| | [pkg/generator.go](https://app.codecov.io/gh/vektra/mockery/pull/710?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vektra#diff-cGtnL2dlbmVyYXRvci5nbw==) | `93.34171% <100.00000%> (+0.02519%)` | :arrow_up: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

rkoehl05 commented 1 year ago

Thanks @RangelReale! I tested with my reproducer and I was able to generate a working mock.

LandonTClipp commented 1 year ago

@RangelReale thanks so much for this. I converted this to a draft because you mentioned this is still a WIP. Please ping me when you're ready for me to review.

RangelReale commented 1 year ago

@RangelReale thanks so much for this. I converted this to a draft because you mentioned this is still a WIP. Please ping me when you're ready for me to review.

@LandonTClipp I updated the description, it should be ready now.

LandonTClipp commented 1 year ago

@RangelReale if you could squash the commits down to one, we can merge away.

RangelReale commented 1 year ago

@RangelReale if you could squash the commits down to one, we can merge away.

rebased to master, see if this is ok.

LandonTClipp commented 1 year ago

Thank you very much for getting this out. I lean heavily on people submitting PRs ❤️