Testing our interfaces

In order to test our application, we'll create an interfaces_test directory inside our interfaces directory.

Since interfaces_test is a different package than interfaces, we are unable to access the private functions and other symbols within the interfaces package. We are able to change our web service internals without breaking any tests. This also helps us focus on the API. We see just what any other client of our API will see when it's deployed and it simplifies our task of creating tests.

We use the testing package from the Go standard library:

package interfaces_testimport (   . "interfaces"   . "utils"   "infrastructure"   "github.com/pkg/errors"   "io/ioutil"   "net/http"   "net/http/httptest"   "os"   "strings"   "testing")const ...

Get Learning Functional Programming in Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.