This is not the output you are looking for – mocking calls to external binaries

Have you ever struggled when trying to test code that calls out to an external process and then uses the output as part of the implemented business logic? In some cases, it might be possible to use some of the tricks we have discussed so far to decorate our code with hooks that tests can use to mock the executed command's output. Unfortunately, sometimes this will not be possible. For instance, the code under test could import a third-party package that is actually the one that's responsible for executing some external command.

The Chapter04/pinger package exports a function called RoundtripTime. Its job is to calculate the round-trip time for reaching a remote ...

Get Hands-On Software Engineering with Golang 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.