I'm a little confused when it comes to testing in Go. I've read that abstracting to interfaces should be the ideal way to go in some cases, in other cases I see TestTables. I'm not too sure when to apply either one. For instance, how would one go about testing the function below.
type User{
Name string `json:"name"`
IsMarried bool `json:"isMarried"`
Nicknames []string `json:"nicknames"`
}
func (u *User) Create() (*http.Response, error) {
data, err := json.Marshal(u)
if err != nil {
return nil, err
}
urll := EndpointBase+"/users"
req, err := http.NewRequest(http.MethodPost, urll, bytes.NewReader(data))
if err != nil {
return nil, err
}
resp, err := auth.Session.Client.Do(req)
if err != nil {
return nil, err
}
return resp, nil
}