Creating a mock db type

Inside our backend/src/dblayer folder, let's add a new file called mockdblayer.go. Inside this new file, let's create a type called MockDBLayer:

package dblayerimport (  "encoding/json"  "fmt"  "strings"  "github.com/PacktPublishing/Hands-On-Full-Stack-Development-with-Go/tree/master/Chapter08/backend/src/models")type MockDBLayer struct { err error  products []models.Product  customers []models.Customer  orders []models.Order}

The MockDBLayer type hosts four types:

  • err: This is an error type that we can set at will whenever we need to simulate an error scenario. We'll look at how to use it when it's time to write our unit tests.
  • products: This is where we store our mock list of products.
  • customers: This is where we store ...

Get Hands-On Full Stack Development with 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.