Skip to content

Commit

Permalink
Update BatchWriteItem to look through entire slice of expectations ra…
Browse files Browse the repository at this point in the history
…ther than only checking in order
  • Loading branch information
Jake Huggart committed Jul 16, 2019
1 parent 6ff0676 commit f75460a
Showing 1 changed file with 7 additions and 11 deletions.
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)
}

0 comments on commit f75460a

Please sign in to comment.