I'm trying to learn to write tests in golang on a personal project of mine.
Bunch of the functions in my project are using net
package, however since I'm new to this I don't know how to mock the functions from packages such as net
one which are interacting with the host's devices.
To make my question more concrete, I have a function similar to this:
func NewThingy(ifcName string) (*Thingy, error) {
if ifc, err := net.InterfaceByName(ifcName); err == nil {
return nil, fmt.Errorf("Interface name %s already assigned on the host", ifcName)
}
....
return &Thingy{
ifc: ifc,
}, nil
}
Thingy is clearly defined as:
type Thingy struct {
ifc *net.Interface
}
Anyone could give me any hints how to go about testing code like this ?
Thanks