forked from LeanerCloud/AutoSpotting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock_test.go
213 lines (170 loc) · 6.51 KB
/
mock_test.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// Copyright (c) 2016-2019 Cristian Măgherușan-Stanciu
// Licensed under the Open Software License version 3.0
package autospotting
import (
"reflect"
"testing"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/aws/aws-sdk-go/service/autoscaling/autoscalingiface"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go/service/cloudformation/cloudformationiface"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ec2/ec2iface"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/aws/aws-sdk-go/service/lambda/lambdaiface"
)
func CheckErrors(t *testing.T, err error, expected error) {
if err != nil && expected != nil && !reflect.DeepEqual(err, expected) {
t.Errorf("Error received: '%v' expected '%v'",
err.Error(), expected.Error())
}
}
// All fields are composed of the abbreviation of their method
// This is useful when methods are doing multiple calls to AWS API
type mockEC2 struct {
ec2iface.EC2API
// DescribeSpotPriceHistoryPages output
dsphpo []*ec2.DescribeSpotPriceHistoryOutput
// DescribeSpotPriceHistoryPages error
dsphperr error
// DescribeInstancesOutput
dio *ec2.DescribeInstancesOutput
// DescribeInstancesPages error
diperr error
// DescribeInstanceAttribute
diao *ec2.DescribeInstanceAttributeOutput
diaerr error
// Terminate Instance
tio *ec2.TerminateInstancesOutput
tierr error
// Describe Regions
dro *ec2.DescribeRegionsOutput
drerr error
// Delete Tags
dto *ec2.DeleteTagsOutput
dterr error
// DescribeLaunchTemplateVersionsOutput
dltvo *ec2.DescribeLaunchTemplateVersionsOutput
dltverr error
// WaitUntilInstanceRunning error
wuirerr error
}
func (m mockEC2) DescribeSpotPriceHistoryPages(in *ec2.DescribeSpotPriceHistoryInput, f func(*ec2.DescribeSpotPriceHistoryOutput, bool) bool) error {
for i, page := range m.dsphpo {
f(page, i == len(m.dsphpo)-1)
}
return m.dsphperr
}
func (m mockEC2) DescribeInstancesPages(in *ec2.DescribeInstancesInput, f func(*ec2.DescribeInstancesOutput, bool) bool) error {
f(m.dio, true)
return m.diperr
}
func (m mockEC2) DescribeInstanceAttribute(in *ec2.DescribeInstanceAttributeInput) (*ec2.DescribeInstanceAttributeOutput, error) {
return m.diao, m.diaerr
}
func (m mockEC2) TerminateInstances(*ec2.TerminateInstancesInput) (*ec2.TerminateInstancesOutput, error) {
return m.tio, m.tierr
}
func (m mockEC2) DescribeRegions(*ec2.DescribeRegionsInput) (*ec2.DescribeRegionsOutput, error) {
return m.dro, m.drerr
}
func (m mockEC2) DeleteTags(*ec2.DeleteTagsInput) (*ec2.DeleteTagsOutput, error) {
return m.dto, m.dterr
}
func (m mockEC2) DescribeLaunchTemplateVersions(*ec2.DescribeLaunchTemplateVersionsInput) (*ec2.DescribeLaunchTemplateVersionsOutput, error) {
return m.dltvo, m.dltverr
}
func (m mockEC2) WaitUntilInstanceRunning(*ec2.DescribeInstancesInput) error {
return m.wuirerr
}
// All fields are composed of the abbreviation of their method
// This is useful when methods are doing multiple calls to AWS API
type mockASG struct {
autoscalingiface.AutoScalingAPI
// Detach Instances
dio *autoscaling.DetachInstancesOutput
dierr error
// Terminate Instances
tiiasgo *autoscaling.TerminateInstanceInAutoScalingGroupOutput
tiiasgerr error
// Attach Instances
aio *autoscaling.AttachInstancesOutput
aierr error
// Describe Launch Config
dlco *autoscaling.DescribeLaunchConfigurationsOutput
dlcerr error
// Update AutoScaling Group
uasgo *autoscaling.UpdateAutoScalingGroupOutput
uasgerr error
// Describe Tags
dto *autoscaling.DescribeTagsOutput
// Describe AutoScaling Group
dasgo *autoscaling.DescribeAutoScalingGroupsOutput
dasgerr error
// Describe AutoScalingInstances
dasio *autoscaling.DescribeAutoScalingInstancesOutput
dasierr error
// DescribeLifecycleHooks
dlho *autoscaling.DescribeLifecycleHooksOutput
dlherr error
// CreateOrUpdateTags
couto *autoscaling.CreateOrUpdateTagsOutput
couterr error
}
func (m mockASG) DetachInstances(*autoscaling.DetachInstancesInput) (*autoscaling.DetachInstancesOutput, error) {
return m.dio, m.dierr
}
func (m mockASG) TerminateInstanceInAutoScalingGroup(*autoscaling.TerminateInstanceInAutoScalingGroupInput) (*autoscaling.TerminateInstanceInAutoScalingGroupOutput, error) {
return m.tiiasgo, m.tiiasgerr
}
func (m mockASG) AttachInstances(*autoscaling.AttachInstancesInput) (*autoscaling.AttachInstancesOutput, error) {
return m.aio, m.aierr
}
func (m mockASG) DescribeLaunchConfigurations(*autoscaling.DescribeLaunchConfigurationsInput) (*autoscaling.DescribeLaunchConfigurationsOutput, error) {
return m.dlco, m.dlcerr
}
func (m mockASG) UpdateAutoScalingGroup(*autoscaling.UpdateAutoScalingGroupInput) (*autoscaling.UpdateAutoScalingGroupOutput, error) {
return m.uasgo, m.uasgerr
}
func (m mockASG) DescribeTagsPages(input *autoscaling.DescribeTagsInput, function func(*autoscaling.DescribeTagsOutput, bool) bool) error {
function(m.dto, true)
return nil
}
func (m mockASG) DescribeAutoScalingGroups(input *autoscaling.DescribeAutoScalingGroupsInput) (*autoscaling.DescribeAutoScalingGroupsOutput, error) {
return m.dasgo, m.dasgerr
}
func (m mockASG) DescribeAutoScalingGroupsPages(input *autoscaling.DescribeAutoScalingGroupsInput, function func(*autoscaling.DescribeAutoScalingGroupsOutput, bool) bool) error {
function(m.dasgo, true)
return nil
}
func (m mockASG) DescribeAutoScalingInstances(inout *autoscaling.DescribeAutoScalingInstancesInput) (*autoscaling.DescribeAutoScalingInstancesOutput, error) {
return m.dasio, m.dasierr
}
func (m mockASG) DescribeLifecycleHooks(*autoscaling.DescribeLifecycleHooksInput) (*autoscaling.DescribeLifecycleHooksOutput, error) {
return m.dlho, m.dlherr
}
func (m mockASG) CreateOrUpdateTags(*autoscaling.CreateOrUpdateTagsInput) (*autoscaling.CreateOrUpdateTagsOutput, error) {
return m.couto, m.couterr
}
// All fields are composed of the abbreviation of their method
// This is useful when methods are doing multiple calls to AWS API
type mockCloudFormation struct {
cloudformationiface.CloudFormationAPI
// DescribeStacks
dso *cloudformation.DescribeStacksOutput
dserr error
}
func (m mockCloudFormation) DescribeStacks(*cloudformation.DescribeStacksInput) (*cloudformation.DescribeStacksOutput, error) {
return m.dso, m.dserr
}
// All fields are composed of the abbreviation of their method
// This is useful when methods are doing multiple calls to AWS API
type mockLambda struct {
lambdaiface.LambdaAPI
// Invoke
io *lambda.InvokeOutput
ierr error
}
func (m mockLambda) Invoke(*lambda.InvokeInput) (*lambda.InvokeOutput, error) {
return m.io, m.ierr
}