The article discusses how to test a function that calls a dependency in other goroutines, which can make the test inconsistent. To solve this problem, the author suggests using Go’s sync.WaitGroup and GoMock’s .Do method. The article provides sample code for testing a service using these methods.
Tag: Golang
This article explains how to use GoMock, a mocking framework for the Go programming language, to mock external dependencies in order to facilitate unit testing. The article provides step-by-step instructions for generating a mock instance of an interface using GoMock, as well as an example test function that uses the mock to test the behavior of a service layer.
The errgroup package is a Go library that makes it easy to run a bunch of tasks concurrently and then cry in despair if any of them fail. So don’t let concurrent tasks ruin your day anymore, give the errgroup package a try and enjoy the peace of mind that comes with knowing that your tasks are being managed and your errors are being caught.
Breaking down the three laws of TDD.