Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/elliotchance/mocksqs

📤 In-memory implementation of SQS ideal for unit testing.
https://github.com/elliotchance/mocksqs

aws mock sqs unit-testing

Last synced: about 1 month ago
JSON representation

📤 In-memory implementation of SQS ideal for unit testing.

Awesome Lists containing this project

README

        

# 📤 github.com/elliotchance/mocksqs

[![Build Status](https://travis-ci.org/elliotchance/mocksqs.svg?branch=master)](https://travis-ci.org/elliotchance/mocksqs)
[![GoDoc](https://godoc.org/github.com/elliotchance/mocksqs?status.svg)](https://godoc.org/github.com/elliotchance/mocksqs)

# Creating the Service

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

```go
url := "https://sqs.us-east-1.amazonaws.com/281910179584/mocksqs"
client := mocksqs.NewWithQueues(map[string][]string{
url: {"foo", "bar"},
})

result, err := client.ReceiveMessage(&sqs.ReceiveMessageInput{
QueueUrl: aws.String(url),
})
```

# 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](https://godoc.org/github.com/elliotchance/mocksqs).

# Events

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

```go
client.GetQueue(url).OnEmptyQueue = func() {
// Clean up, assert, cancel context, etc.
}
```

See the
[documentation for Queue](https://godoc.org/github.com/elliotchance/mocksqs#Queue)
for more information.

# Simulating HTTP Latency

SimulateHTTPLatency when enabled will add a sleep between 20 and 100
milliseconds to each call that would otherwise need to make a HTTP request with
a real SQS client:

```go
client.SimulateHTTPLatency = true
```