You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package test
//go:generate mockery --name TesttypeTestinterface {
Test(_int)
}
the generated code looks like this
// Code generated by mockery v2.9.4. DO NOT EDIT.package mocks
import mock "github.com/stretchr/testify/mock"// Test is an autogenerated mock type for the Test typetypeTeststruct {
mock.Mock
}
// Test provides a mock function with given fields: _func (_m*Test) Test(_int) {
_m.Called(_)
}
The problem here is, that the call _m.Called(_) uses the _ like an actual variable.
Expected behavior
I expected the generated code to look like this
// Code generated by mockery v2.9.4. DO NOT EDIT.package mocks
import mock "github.com/stretchr/testify/mock"// Test is an autogenerated mock type for the Test typetypeTeststruct {
mock.Mock
}
// Test provides a mock function with given fields: _func (_m*Test) Test(mockeryParam0int) {
_m.Called(mockeyParam0)
}
that is, to replace the invalid parameter name with an autogenerated value.
Workaround
Of course, this is solved by giving the parameter in the interface an actual name. However, I think that valid Go code should not cause mockery to generate invalid Go code.
The text was updated successfully, but these errors were encountered:
you can ignore the parameter's name at all in the interfaces:
package test
//go:generate mockery --name TesttypeTestinterface {
Test(int)
}
it generates this code:
// Code generated by mockery v2.9.4. DO NOT EDIT.package mocks
import mock "github.com/stretchr/testify/mock"// Test is an autogenerated mock type for the Test typetypeTeststruct {
mock.Mock
}
// Test provides a mock function with given fields: _a0func (_m*Test) Test(_a0int) {
_m.Called(_a0)
}
Observed behavior
When generating mocks for an interface like this
the generated code looks like this
The problem here is, that the call
_m.Called(_)
uses the_
like an actual variable.Expected behavior
I expected the generated code to look like this
that is, to replace the invalid parameter name with an autogenerated value.
Workaround
Of course, this is solved by giving the parameter in the interface an actual name. However, I think that valid Go code should not cause mockery to generate invalid Go code.
The text was updated successfully, but these errors were encountered: