Created
February 3, 2017 18:33
-
-
Save herman-rogers/5807225ea90680c80c2d5442b32bb67c to your computer and use it in GitHub Desktop.
Mocking Amazon AWS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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