In-memory SQS For Unit Testing

Elliot Chance
Dec 11, 2019 · 1 min read
Photo by Levi Jones on Unsplash

If you need an in-memory, functional SQS client during unit tests you can now use github.com/elliotchance/mocksqs.

Getting Started

The simplest way to create a new SQS service is with mocksqs.New(). However, if you need queues prepopulated you can use mocksqs.NewWithQueues():

Wherever you pass around an SQS client in your application, you should use the sqsiface.SQSAPI interface.

Supported Functionality

Only some of the common SQS methods are implemented. Methods not implemented will panic.

You can view the specific implementation details in the godoc documentation.

Events

Functions can be set on queues to help with unit testing life cycle. For
example:

See the documentation for Queue for more information.

Simulating HTTP Latency

When enabled a sleep between 20 and 100 milliseconds is added to each call that would otherwise need to make a HTTP request with a real SQS client:

Elliot Chance

Written by

I’m a data nerd and TDD enthusiast from Sydney. I love exploring new technologies and working on modern ways to solve age old problems 🤓 elliotchance@gmail.com

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade