Unit tests
We have covered many useful features for automated testing of Go applications and are now ready to illustrate how to use them in our microservice code. First, we are going to start with unit tests — tests of individual units of code, such as structures and individual functions.
Let’s walk through the process of implementing unit tests for our code using the metadata service controller as an example. Currently, our controller file looks like this:
package metadata
import (
"context"
"movieexample.com/metadata/pkg/model"
)
type metadataRepository interface {
Get(ctx context.Context, id string) (*model.Metadata, error)
}
// Controller defines a metadata service controller.
Type Controller struct {
repo metadataRepository
}
// New creates a metadata service controller.
Func New(repo metadataRepository) *Controller {
return...