Making the real option explicit
Closed this issue · 1 comments
rahat@rahat-Inspiron-5515:~/Desktop/TukuRetail/tukuReatail@back$ mockcompose mockcompose - Please specify at least one real method name with -real option
Hey!! your package is great! But I have a concerns that i think if fixed then this package would be more easy to use.
We need specify the real methods explicitly but think like i have 20 methods and i just one to mock one so will i have to write the other 19 methods by including their names? that's impractical isn't it? Why not auto explicitly consider all other function as real function that are not included in -mock?
Moreover I don't know why but your cli is also generating wrong files:
//go:generate mockcompose -n TestCognitoAuthenticator -c CognitoAuthenticator -real EmployeeLogin -mock errorHandler -mock isUserInGroup
generates:
// CODE GENERATED AUTOMATICALLY WITH github.com/kelveny/mockcompose
// THIS FILE SHOULD NOT BE EDITED BY HAND
package auth
import (
"github.com/stretchr/testify/mock"
)
type TestCognitoAuthenticator struct {
CognitoAuthenticator
mock.Mock
}
func (m *TestCognitoAuthenticator) isUserInGroup(username string, groupName string) (bool, error) {
_mc_ret := m.Called(username, groupName)
var _r0 bool
if _rfn, ok := _mc_ret.Get(0).(func(string, string) bool); ok {
_r0 = _rfn(username, groupName)
} else {
if _mc_ret.Get(0) != nil {
_r0 = _mc_ret.Get(0).(bool)
}
}
var _r1 error
if _rfn, ok := _mc_ret.Get(1).(func(string, string) error); ok {
_r1 = _rfn(username, groupName)
} else {
_r1 = _mc_ret.Error(1)
}
return _r0, _r1
}
Thanks for your feedback.
i have 20 methods and i just one to mock one so will i have to write the other 19 methods by including their names?
A method has its own calling closure which is usually smaller than the whole set of method functions. Since real
option cause mockcompose
to copy code around, thus you currently have to explicitly setup
that's impractical isn't it?
A improvement could be added, for example, let mockcompose
figure out the calling closure and copy code implicitly. I'm currently under a medical condition, will look into such option once I'm recovered. Hopefully this option will make it easier to use
Why not auto explicitly consider all other function as real function that are not included in -mock?
Yeah, this involve a bit more work as I mentioned above, but it is a good option to go after. Please look forward to updates of it