I was writing some stuff that programmatically executed terraform via Hashicorp's terraform-exec library this week. This works by interacting with a terraform executable that you provide (along with a working directory) to the NewTerraform constructor. Here's the trick: when testing this code it does not need to interact with the real executable. It can subprocess… Continue reading How to Test Code that Executes Subprocesses
Category: Go
Map and Filter with Generics and Go 1.23 Iterators
I found myself missing map and filter constructs for some small things in Go, and here we are. Go 1.18 got generics, and I've admittedly not used them too much in real apps. Go 1.23 brought iterators. The combo of these two makes map/filter pretty easy to create. They play nicely with the utilities in… Continue reading Map and Filter with Generics and Go 1.23 Iterators
Test Setup and Teardown Methods in Go
Dependency Inversion with Client Side Interfaces in Go
One interesting thing about Go is that it lacks and explicit implements keyword for interfaces. If you want to implement an interface, there's no extra step. As long as function signatures match the interface, or function type declaration in those cases, the interface is implemented. The same could be said of Python protocols too. Coming… Continue reading Dependency Inversion with Client Side Interfaces in Go
Dependency Inversion in Go HTTP Handlers
This post has a lot of Go, but I suspect its relevant to any programming language with first class functions. I've been doing some more work in Go the last month or so. One bit of advice I really like and have been following from how I write HTTP service in Go after 13 years… Continue reading Dependency Inversion in Go HTTP Handlers
Running Database Integration Tests in Go
I'm working through writing a Go app backed by a PostgreSQL database (using sqlx). Whenever I'm writing code that interacts with a database, I want to make sure that I'm testing against the real thing -- especially when using plain old SQL statements where dialects can differ between databases. One thing I do in PHP… Continue reading Running Database Integration Tests in Go
Beware Blocking Channel Sends in Go
I recently got bit by a blocking channel send in Go causing an entire program to hang. I had gorouting thing running on a timer to check something periodically and send results to a channel. Another goroutine was consuming from the channel. Notably, the channel was unbuffered intentially as I assume the consumer would also… Continue reading Beware Blocking Channel Sends in Go
OAuth PKCE with Go
This is going to describe how to do Proof Key for Code Exchange (PKCE) with Go's golang.org/x/oauth2. A Brief Overview of PKCE PKCE is meant to be an extra layer of client authentication during the authorization code grant flow with public oauth clients (native apps, single page JS apps -- basically anything that cant' kep… Continue reading OAuth PKCE with Go




