-
Notifications
You must be signed in to change notification settings - Fork 51
/
scan.go
104 lines (79 loc) · 3.35 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
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
104
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 *ScanExpectation) Table(table string) *ScanExpectation {
e.table = &table
return e
}
// WillReturns - method for set desired result
func (e *ScanExpectation) WillReturns(res dynamodb.ScanOutput) *ScanExpectation {
e.output = &res
return e
}
// Scan - this func will be invoked when test running matching expectation with actual input
func (e *MockDynamoDB) Scan(input *dynamodb.ScanInput) (*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 &dynamodb.ScanOutput{}, 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 &dynamodb.ScanOutput{}, fmt.Errorf("Scan Table Expectation Not Found")
}
// ScanWithContext - this func will be invoked when test running matching expectation with actual input
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 &dynamodb.ScanOutput{}, 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 &dynamodb.ScanOutput{}, fmt.Errorf("Scan Table With Context Expectation Not Found")
}
// ScanPages - this func will be invoked when test running matching expectation with actual input
func (e *MockDynamoDB) ScanPages(input *dynamodb.ScanInput, fn func(*dynamodb.ScanOutput, bool) bool) 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 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:]...)
fn(x.output, true)
return nil
}
return fmt.Errorf("Scan Table By Page Expectation Not Found")
}
// ScanPagesWithContext - this func will be invoked when test running matching expectation with actual input
func (e *MockDynamoDB) ScanPagesWithContext(ctx aws.Context, input *dynamodb.ScanInput, fn func(*dynamodb.ScanOutput, bool) bool, opts ...request.Option) 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 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:]...)
fn(x.output, true)
return nil
}
return fmt.Errorf("Scan Table By Page With Context Expectation Not Found")
}