The simplest way to create a new SQS service is with mocksqs.New()
. However,
if you need queues prepopulated you can use mocksqs.NewWithQueues()
:
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),
})
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.
Functions can be set on queues to help with unit testing life cycle. For example:
client.GetQueue(url).OnEmptyQueue = func() {
// Clean up, assert, cancel context, etc.
}
See the documentation for Queue for more information.
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:
client.SimulateHTTPLatency = true