November 2018
Intermediate to advanced
346 pages
8h 12m
English
We can test Converter without making any code changes at all. The first step is to define an HTTP server that returns the response we need. In the following example, the server is returning the same as the mock in the previous section:
server := httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) { payload := []byte(`invalid payload`) response.Write(payload)}))
Then we take the URL from the test server and pass it in as a config to Converter, as shown in the following example:
cfg := &testConfig{ baseURL: server.URL, apiKey: "",}converter := NewConverter(cfg)
And now, the following example shows how we can perform the HTTP call and validate the response, as we did ...
Read now
Unlock full access