Skip to content

Commit

Permalink
Add more ctx methods
Browse files Browse the repository at this point in the history
  • Loading branch information
cfilby committed Jan 27, 2020
1 parent 30b7787 commit f0ef1b0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
21 changes: 21 additions & 0 deletions scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package dynamock

import (
"fmt"
"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 @@ -37,3 +39,22 @@ func (e *MockDynamoDB) Scan(input *dynamodb.ScanInput) (*dynamodb.ScanOutput, er

return nil, fmt.Errorf("Scan Table Expectation Not Found")
}

func (e *MockDynamoDB) ScanWithContext(ctx aws.Context, input *dynamodb.ScanInput, opts ...request.Option) (*dynamodb.ScanOutput, error) {
if len(e.dynaMock.ScanExpect) > 0 {
x := e.dynaMock.ScanExpect[0] //get first element of expectation

if x.table != nil {
if *x.table != *input.TableName {
return nil, fmt.Errorf("Expect table %s but found table %s", *x.table, *input.TableName)
}
}

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

return x.output, nil
}

return nil, fmt.Errorf("Scan Table With Context Expectation Not Found")
}
33 changes: 33 additions & 0 deletions transact_write_items.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package dynamock

import (
"fmt"
"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 @@ -47,4 +49,35 @@ func (e *MockDynamoDB) TransactWriteItems(input *dynamodb.TransactWriteItemsInpu
}

return nil, fmt.Errorf("Transact Write Items Table Expectation Not Found")
}

func (e *MockDynamoDB) TransactWriteItemsWithContext(ctx aws.Context, input *dynamodb.TransactWriteItemsInput, opts ...request.Option) (*dynamodb.TransactWriteItemsOutput, error) {
if len(e.dynaMock.TransactWriteItemsExpect) > 0 {
x := e.dynaMock.TransactWriteItemsExpect[0] //get first element of expectation

foundTable := false

if x.table != nil {
for _, item := range input.TransactItems {
if (item.Update != nil && x.table == item.Update.TableName) ||
(item.Put != nil && x.table == item.Put.TableName) ||
(item.Delete != nil && x.table == item.Delete.TableName) {
foundTable = true
}
}

if foundTable == false {
return nil, fmt.Errorf("Expect table %s not found", *x.table)
}
}

// delete first element of expectation

e.dynaMock.TransactWriteItemsExpect = append(e.dynaMock.TransactWriteItemsExpect[:0],
e.dynaMock.TransactWriteItemsExpect[1:]...)

return x.output, nil
}

return nil, fmt.Errorf("Transact Write Items Table With Context Expectation Not Found")
}

0 comments on commit f0ef1b0

Please sign in to comment.