/plushcap/analysis/incident-io/golang-client-mocks

Using context.Context to mock API clients

What's this blog post about?

The text discusses a pattern for mocking external client libraries in Go while keeping the code simple and ensuring all the code down a call stack uses the same mock client. This is achieved by generating a mock using tools like interfacer and gomock, and then injecting it with context.Context. The resulting test suite improves developer productivity when writing tests.

Company
Incident.io

Date published
Dec. 21, 2021

Author(s)
Lawrence Jones

Word count
1370

Hacker News points
None found.

Language
English


By Matt Makai. 2021-2024.