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