forked from groovili/go-dynamock-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwait_table.go
43 lines (31 loc) · 1.07 KB
/
wait_table.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package dynamock
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
)
// Table - method for set Table expectation
func (e *WaitTableExistExpectation) Table(table string) *WaitTableExistExpectation {
e.table = &table
return e
}
// WillReturn - method for set desired result
func (e *WaitTableExistExpectation) WillReturn(err error) *WaitTableExistExpectation {
e.err = err
return e
}
// WaitUntilTableExists - this func will be invoked when test running matching expectation with actual input
func (e *MockDynamoDB) WaitUntilTableExists(ctx context.Context, input *dynamodb.DescribeTableInput, opt ...aws.WaiterOption) error {
if len(e.dynaMock.WaitTableExistExpect) == 0 {
return ErrNoExpectation
}
x := e.dynaMock.WaitTableExistExpect[0]
if x.table == nil {
return ErrNoTable
}
if aws.StringValue(x.table) != aws.StringValue(input.TableName) {
return ErrTableExpectationMismatch
}
e.dynaMock.WaitTableExistExpect = append(e.dynaMock.WaitTableExistExpect[:0], e.dynaMock.WaitTableExistExpect[1:]...)
return nil
}