Testing the restdb Package

Let’s learn how to test the restdb package.

We'll cover the following

The RESTful server is developed in ~/go/src/github.com/Educative-Content/rest-api—if we do not plan on making it available to the world, we do not need to create a separate GitHub repository for it. However, we do want to be able to share it with you, so the GitHub repository for the server is https://github.com/Educative-Content/rest-api.

Coding example

Before continuing with the server implementation, we use the restdb package to make sure that it is working as expected before using it in the RESTful server implementation. The presented utility uses functions from restdb; we do not have to test every possible usage of the restdb package—just make sure that it works and that it connects to the PostgreSQL database. For this reason, we are going to create a separate command-line utility called useRestdb.go that contains the next code and is in the test-db directory. The most important detail in that file is the use of restdb.User in the code because this is the structure that is needed by the restdb package. We cannot pass a different structure as a parameter to the functions of restdb.

Initializing modules and running useRestdb.go produces the next kind of output:

Get hands-on with 1400+ tech skills courses.