Say I have 2 Functions func GetCar()
and func PrintFormat()
. For obvious reasons, PrintFormat
is not part of the interface.
Both the functions are tied to car struct{}
via function receivers.
How can I test GetCar
given I have a dependency on func PrintFormat()
.
Is it possible to mock func PrintFormat()
to output some arbitrary value during tests that I can work with ?
type Car interface {
GetCar(id string)
}
type car struct {
name string
data data
printFormat string
}
func (c *car) GetCar(id string) {
info := c.printFormat(id)
fmt.Println(info)
}
func (c *car) printFormat(id string) {
return DoSomething(id, c.printFormat)
}