-
Notifications
You must be signed in to change notification settings - Fork 50
/
query.go
103 lines (79 loc) · 3.41 KB
/
query.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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"
)
// Table - method for set Table expectation
func (e *QueryExpectation) Table(table string) *QueryExpectation {
e.table = &table
return e
}
// WillReturns - method for set desired result
func (e *QueryExpectation) WillReturns(res dynamodb.QueryOutput) *QueryExpectation {
e.output = &res
return e
}
// Query - this func will be invoked when test running matching expectation with actual input
func (e *MockDynamoDB) Query(input *dynamodb.QueryInput) (*dynamodb.QueryOutput, error) {
if len(e.dynaMock.QueryExpect) > 0 {
x := e.dynaMock.QueryExpect[0] //get first element of expectation
if x.table != nil {
if *x.table != *input.TableName {
return &dynamodb.QueryOutput{}, fmt.Errorf("Expect table %s but found table %s", *x.table, *input.TableName)
}
}
// delete first element of expectation
e.dynaMock.QueryExpect = append(e.dynaMock.QueryExpect[:0], e.dynaMock.QueryExpect[1:]...)
return x.output, nil
}
return &dynamodb.QueryOutput{}, fmt.Errorf("Query Table Expectation Not Found")
}
// QueryWithContext - this func will be invoked when test running matching expectation with actual input
func (e *MockDynamoDB) QueryWithContext(ctx aws.Context, input *dynamodb.QueryInput, options ...request.Option) (*dynamodb.QueryOutput, error) {
if len(e.dynaMock.QueryExpect) > 0 {
x := e.dynaMock.QueryExpect[0] //get first element of expectation
if x.table != nil {
if *x.table != *input.TableName {
return &dynamodb.QueryOutput{}, fmt.Errorf("Expect table %s but found table %s", *x.table, *input.TableName)
}
}
// delete first element of expectation
e.dynaMock.QueryExpect = append(e.dynaMock.QueryExpect[:0], e.dynaMock.QueryExpect[1:]...)
return x.output, nil
}
return &dynamodb.QueryOutput{}, fmt.Errorf("Query Table With Context Expectation Not Found")
}
// QueryPages - this func will be invoked when test running matching expectation with actual input
func (e *MockDynamoDB) QueryPages(input *dynamodb.QueryInput, fn func(*dynamodb.QueryOutput, bool) bool) error {
if len(e.dynaMock.QueryExpect) > 0 {
x := e.dynaMock.QueryExpect[0] //get first element of expectation
if x.table != nil {
if *x.table != *input.TableName {
return fmt.Errorf("Expect table %s but found table %s", *x.table, *input.TableName)
}
}
// delete first element of expectation
e.dynaMock.QueryExpect = append(e.dynaMock.QueryExpect[:0], e.dynaMock.QueryExpect[1:]...)
fn(x.output, true)
return nil
}
return fmt.Errorf("Query Table By Page Expectation Not Found")
}
// QueryPagesWithContext - this func will be invoked when test running matching expectation with actual input
func (e *MockDynamoDB) QueryPagesWithContext(ctx aws.Context, input *dynamodb.QueryInput, fn func(*dynamodb.QueryOutput, bool) bool, options ...request.Option) error {
if len(e.dynaMock.QueryExpect) > 0 {
x := e.dynaMock.QueryExpect[0] //get first element of expectation
if x.table != nil {
if *x.table != *input.TableName {
return fmt.Errorf("Expect table %s but found table %s", *x.table, *input.TableName)
}
}
// delete first element of expectation
e.dynaMock.QueryExpect = append(e.dynaMock.QueryExpect[:0], e.dynaMock.QueryExpect[1:]...)
fn(x.output, true)
return nil
}
return fmt.Errorf("Query Table By Page With Context Expectation Not Found")
}