-
Notifications
You must be signed in to change notification settings - Fork 416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add resolve-type-alias
parameter
#843
Add resolve-type-alias
parameter
#843
Conversation
07ba230
to
4ced14b
Compare
c3a9cee
to
13fc607
Compare
Do I understand correctly that this PR makes mocks to be created in |
Not quite. The relevant part of this PR is here: https://github.com/vektra/mockery/pull/843/files#diff-9233145a2afa8ecc02f5d52807d154baf4d2e2a118f22721cb80277f9b2e6d82R541-R553 The You can see the two tests that demonstrate the new behavior: https://github.com/vektra/mockery/pull/843/files#diff-f52d7d97345ebe96212f5c1dca1585a844ef7af865ec3273358bc9b6597c0c83 |
@LandonTClipp looks like it now expands type to a struct definition: -// Code generated by mockery v2.44.1. DO NOT EDIT.
+// Code generated by mockery v2.49.0. DO NOT EDIT.
....
-func (_m *CassandraAgentClientPool) GetClientForInstance(_a0 *manualv1alpha1.Instance) (pb.CassandraAgentClient, error) {
+func (_m *CassandraAgentClientPool) GetClientForInstance(_a0 *struct {
+ v1.TypeMeta
+ v1.ObjectMeta
+ Spec manualv1alpha1.InstanceSpec `json:"spec"`
+ Status manualv1alpha1.InstanceStatus `json:"status,omitempty"`
+}) (pb.CassandraAgentClient, error) { Is this expected? |
Can you show the definition of your type? |
import (
// ...
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// ...
type Instance struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec InstanceSpec `json:"spec"`
Status InstanceStatus `json:"status,omitempty"`
} |
I'm not able to replicate this behavior when using the |
I used your reproducer for the original issue (modifying the Makefile so I can use the latest mockery). package p
type T = int
type Instance struct {
attribute int
}
//go:generate mockery --quiet --name I
type I interface{ F(T) }
//go:generate mockery --quiet --name I2
type I2 interface{ F(Instance) } The generated mock file for I2: // Code generated by mockery v2.49.0. DO NOT EDIT.
package mocks
import (
p "mockery-issue/p"
mock "github.com/stretchr/testify/mock"
)
// I2 is an autogenerated mock type for the I2 type
type I2 struct {
mock.Mock
}
// F provides a mock function with given fields: _a0
func (_m *I2) F(_a0 p.Instance) {
_m.Called(_a0)
} You can see it is not writing out the struct definition, so I'm unclear how this is happening for you. |
Here I could reproduce it: max-melentyev/mockery-issue@ee08ac9 Aliased struct gets inlined. |
I'm able to reproduce it as well, working on a fix. |
@max-melentyev found in vektra#843 that type aliases to structs were being rendered as a struct literal. The problem was that we need the type of the right hand side of the alias definition, not the underlying type itself.
The merged PR above should resolve the issue for you. |
Description
Please include a summary of the changes and the related issue. Please also include relevant motivation and context.