Closed safaci2000 closed 3 months ago
Does https://vektra.github.io/mockery/latest/features/#replace-types do you what you need?
@LandonTClipp that does seem to work.
I added this to my config which seems to work.
replace-type:
- github.com/go-jet/jet/v2/internal/jet=github.com/go-jet/jet/v2/postgres
I didn't see any concrete examples on: https://vektra.github.io/mockery/latest/configuration/#parameter-descriptions
but if there's a smarter way of doing this let me know.
As a side note, do you know why this is acting this way? It's seems peculiar to me. I have other repo classes that don't behave that way but I can't really tell what is different about this class in particular.
Yes we do know why it happens, the reasons are enumerated in the link I posted above.
Basically, the Go AST did not provide any typing information for aliases. They would transparently resolve to the aliased type, so it was impossible for anything parsing the AST to know it was an alias.
I did do an investigation of this over a year ago to see if there was a fix with this new gotypesalias
flag you can provide to the go build tool: https://github.com/vektra/mockery/issues/763
We now have go/types support, but I have yet to see if the compiler and export format preserve the typing info during compilation, which is also necessary: https://github.com/golang/go/issues/64208
It doesn't appear that the Go devs have completely fixed this yet, so I'm doubtful there's anything further we can do.
Okay thank you for the info. I'll close this ticket out and keep my fingers crossed regarding the golang ticket.
PLEASE READ
DO NOT submit tickets without first using the latest version of Go, clearing your local golang package cache, and re-building mockery using the latest Go version and the latest version of mockery. Please provide evidence this has been done in your issue. Failure to provide this evidence will likely result in your issue being closed.
Description
I'm currently using jet which lets me connect to postgres and run some queries. I'm not sure why this is the behavior and it's only in one of my repo files though the imports look similar.
In my class i import:
The generated mocked class looks like this:
which obviously fails as it's trying to import an internal library. postgres, exports some of the internal equivalent from internal/jet that I'm using.
Mockery Version
2.44.1
Go Version
1.23.0
Installation Method
Steps to Reproduce
run: mockery
Expected Behavior
Mock should not import an internal library.
Actual Behavior
Imported an internal library.
Related files can be found here: https://gist.github.com/safaci2000/34b1cef47a0b733d5cd73337bed16484