Improving test scenario coverage

The first thing we will do is break the dependence on the upstream currency service in the test. Then, we will proceed to add tests to cover additional scenarios that we couldn't cover before. This is what our test currently looks like:

func TestRegisterHandler_ServeHTTP(t *testing.T) {   // ensure the test always fails by giving it a timeout   ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)   defer cancel()   // Create and start a server   // With out current implementation, we cannot test this handler without   // a full server as we need the mux.   address, err := startServer(ctx)   require.NoError(t, err)   // build inputs   validRequest := buildValidRequest()   response, err := http.Post("http://"

Get Hands-On Dependency Injection in Go now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.