Home / Companies / Cloudflare / Blog / Post Details
Content Deep Dive

Go interfaces make test stubbing easy

Blog post from Cloudflare

Post Details
Company
Date Published
Author
John Graham-Cumming
Word Count
666
Language
English
Hacker News Points
-
Summary

In a piece of software designed for image compression, John Graham-Cumming discovered an effective use of interfaces in Go programming language. The Worker package runs jobs in goroutines and expects them to have a "Do" method. By defining a Job interface with the required methods, he was able to create a DummyJob that could be used for testing without needing to configure complex job types. This approach greatly simplified the unit test suite and demonstrated the power of interfaces in Go programming.