Skip to content

Commit

Permalink
Adding BatchWriteItemWithContext
Browse files Browse the repository at this point in the history
This patch introduces BatchWriteItemWithContext API which
has same body of BatchWriteItem.
  • Loading branch information
sangdeug.kim committed Oct 8, 2019
1 parent b1eca1f commit 7ed624a
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions batch_write_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"reflect"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/service/dynamodb"
)

Expand Down Expand Up @@ -38,3 +40,23 @@ func (e *MockDynamoDB) BatchWriteItem(input *dynamodb.BatchWriteItemInput) (*dyn

return nil, fmt.Errorf("Batch Write Item Expectation Not Found")
}

// BatchWriteItemWithContext - this func will be invoked when test running matching expectation with actual input
func (e *MockDynamoDB) BatchWriteItemWithContext(ctx aws.Context, input *dynamodb.BatchWriteItemInput, opt ...request.Option) (*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)
}
}

// 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")
}

0 comments on commit 7ed624a

Please sign in to comment.