Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update BatchWriteItem to look through entire slice of expectations ra… #16

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions batch_write_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@ func (e *BatchWriteItemExpectation) WillReturns(res dynamodb.BatchWriteItemOutpu
// BatchWriteItem - this func will be invoked when test running matching expectation with actual input
func (e *MockDynamoDB) BatchWriteItem(input *dynamodb.BatchWriteItemInput) (*dynamodb.BatchWriteItemOutput, error) {
if len(e.dynaMock.BatchWriteItemExpect) > 0 {
x := e.dynaMock.BatchWriteItemExpect[0] //get first element of expectation

if x.input != nil {
if !reflect.DeepEqual(x.input, input.RequestItems) {
return nil, fmt.Errorf("Expect input %+v but found input %+v", x.input, input.RequestItems)
for i, x := range e.dynaMock.BatchWriteItemExpect {
if x.input != nil {
if reflect.DeepEqual(x.input, input.RequestItems) {
e.dynaMock.BatchWriteItemExpect = append(e.dynaMock.BatchWriteItemExpect[:i], e.dynaMock.BatchWriteItemExpect[i:]...)
return x.output, nil
}
}
}

// delete first element of expectation
e.dynaMock.BatchWriteItemExpect = append(e.dynaMock.BatchWriteItemExpect[:0], e.dynaMock.BatchWriteItemExpect[1:]...)

return x.output, nil
}

return nil, fmt.Errorf("Batch Write Item Expectation Not Found")
return nil, fmt.Errorf("Batch Write Item Expectation Failed. Expected one of %+v to equal %+v", e.dynaMock.BatchWriteItemExpect, input.RequestItems)
}