How to Test HTTP Outbound in Go Using Just the Standard Library

The Go standard library is rich and powerful, but we often find ourselves needing third-party libraries to test HTTP outbound. Similar to testing an HTTP handler with the httptest package, we can also test HTTP outbound either with httptest or by extending the http.RoundTripper package. This article will demonstrate how to test HTTP outbound in Go. Prepare the Playground To ensure we’re on the same page, let’s clone this repository to use as our base code....

April 15, 2024 · 10 min · 2078 words · Jose Sitanggang

How to Test Goroutines in Go

Goroutines are one of the most powerful features in Go. They allow us to run tasks concurrently and are also lightweight compared to threads. However, testing goroutines can be challenging because they execute in a random order. Sometimes, the test may finish before the goroutine completes, causing the test to fail intermittently. In this article, we’ll explore how to test goroutines in Go using just the standard library. Let’s consider this simple example:...

April 9, 2024 · 7 min · 1344 words · Jose Sitanggang