Skip to content

Commit

Permalink
Merge pull request #16 from jhuggart/jhuggart/unordered-batch-write-item
Browse files Browse the repository at this point in the history
Update BatchWriteItem to look through entire slice of expectations ra…
  • Loading branch information
gusaul authored Mar 25, 2020
2 parents 63a3470 + f75460a commit aaeeb0c
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 @@ -24,21 +24,17 @@ 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)
}

// BatchWriteItemWithContext - this func will be invoked when test running matching expectation with actual input
Expand Down

0 comments on commit aaeeb0c

Please sign in to comment.