Error types
// DumbGetter will get the string body of url if it gets a 200
func DumbGetter(url string) (string, error) {
res, err := http.Get(url)
if err != nil {
return "", fmt.Errorf("problem fetching from %s, %v", url, err)
}
if res.StatusCode != http.StatusOK {
return "", fmt.Errorf("did not get 200 from %s, got %d", url, res.StatusCode)
}
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body) // ignoring err for brevity
return string(body), nil
}Problems with this way of testing
What we should do
What does the test do?
Wrapping up
Addendum
Last updated