Content Deep Dive
Using context.Context to mock API clients
Blog post from Incident.io
Post Details
Company
Date Published
Author
Lawrence Jones
Word Count
1,370
Language
English
Hacker News Points
-
Source URL
Summary
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.