Skip to content

Instantly share code, notes, and snippets.

@herman-rogers
Created February 3, 2017 18:33
Show Gist options
  • Save herman-rogers/5807225ea90680c80c2d5442b32bb67c to your computer and use it in GitHub Desktop.
Save herman-rogers/5807225ea90680c80c2d5442b32bb67c to your computer and use it in GitHub Desktop.
Mocking Amazon AWS
type Messenger interface {
GetMessage() (*BuildServiceRequest, error)
DeleteMessage() error
}
type MessengerImpl struct {
session *sqsiface.SQSAPI // Need to use amazon's interface
message *sqs.Message
}
// In your tests you need to mock out session
type MockedSession struct {
sqsiface.SQSAPI
// Mocked functions from the Real amazon api
Response sqs.RecieveMessageOutput
}
// Mock out the functions declared underneath stubbed session
func (m MockedSession) ReceiveMessage(input *sqs.RecieveMessageInput)() { return bullshit response }
// Create a test to use your real code and inject the mocked session
func Test(t *testing.T) {
queue := MessengerImpl {
session: MockedSession{Response:} //inject client here
}
queue.GetMessage() // hits your real code and returns values
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment