Is there any way to spy on methods in Golang?
For example, suppose I have
type Object struct {
A int
B string
C *interface{}
}
func (o *Object) Something(val interface{}) {
o.A = 102
// some other business logic under test
o.SomethingElse(o.C, val)
}
//...
func (o *Object) Process(val interface{}) interface{} {
// some business logic
return 43 // or something else. no me importa ya
}
//...
func (o *Object) SomethingElse(iPtr *interface{}, val interface{}) {
processedVal := o.Process(val)
if iPtr == nil {
iPtr = new(interface{})
}
*iPtr = val
}
In writing a test against Object.Something
, we should not need to care about what's happening in SomethingElse
or the Process
invoked from within. Is there any way, in Golang, to isolate these dependencies?