We should cover all API methods and also cover the details like
- is data properly mapped into the HTTP request
- how does the client react on errors
Instead of calling a internet endpoint in tests (currently it goes against the sandbox) we should mock
the client and contract based tests.
Go provides an easy way to mock the http endpoint like the example shows, we should give it a try:
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"net/http/httptest"
)
func main() {
ts := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello, client")
}))
defer ts.Close()
client := ts.Client()
res, err := client.Get(ts.URL)
if err != nil {
log.Fatal(err)
}
greeting, err := ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s", greeting)
}
Example taken from: https://golang.org/pkg/net/http/httptest/#NewServer
We should cover all API methods and also cover the details like
Instead of calling a internet endpoint in tests (currently it goes against the sandbox) we should mock
the client and contract based tests.
Go provides an easy way to mock the http endpoint like the example shows, we should give it a try:
Example taken from: https://golang.org/pkg/net/http/httptest/#NewServer