forked from groovili/go-dynamock-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.go
50 lines (37 loc) · 1.08 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
package dynamock
import (
"net/http"
"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 *QueryExpectation) Table(table string) *QueryExpectation {
e.table = &table
return e
}
// WillReturn - method for set desired result
func (e *QueryExpectation) WillReturn(res dynamodb.QueryResponse) *QueryExpectation {
e.output = res.QueryOutput
return e
}
// QueryRequest - this func will be invoked when test running matching expectation with actual input
func (e *MockDynamoDB) QueryRequest(input *dynamodb.QueryInput) dynamodb.QueryRequest {
req := dynamodb.QueryRequest{
Request: &aws.Request{
HTTPRequest: &http.Request{},
},
}
if len(e.dynaMock.QueryExpect) == 0 {
req.Error = ErrNoExpectation
return req
}
x := e.dynaMock.QueryExpect[0]
validateInput(input, req.Request)
validateTable(x.table, input.TableName, req.Request)
if req.Error != nil {
return req
}
e.dynaMock.QueryExpect = append(e.dynaMock.QueryExpect[:0], e.dynaMock.QueryExpect[1:]...)
req.Data = x.output
return req
}