forked from LeanerCloud/AutoSpotting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspot_instance_request_test.go
150 lines (144 loc) · 3.07 KB
/
spot_instance_request_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
package autospotting
import (
"errors"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/aws/aws-sdk-go/service/ec2"
)
func Test_waitForAndTagSpotInstance(t *testing.T) {
tests := []struct {
name string
req spotInstanceRequest
er error
}{
{
name: "with WaitUntilSpotInstanceRequestFulfilled error",
req: spotInstanceRequest{
SpotInstanceRequest: &ec2.SpotInstanceRequest{
SpotInstanceRequestId: aws.String(""),
},
region: ®ion{
conf: &Config{},
services: connections{
ec2: mockEC2{
wusirferr: errors.New(""),
},
},
},
asg: &autoScalingGroup{
name: ""},
},
er: errors.New(""),
},
{
name: "without WaitUntilSpotInstanceRequestFulfilled error",
req: spotInstanceRequest{
SpotInstanceRequest: &ec2.SpotInstanceRequest{
SpotInstanceRequestId: aws.String(""),
},
region: ®ion{
conf: &Config{},
services: connections{
ec2: mockEC2{
dsiro: &ec2.DescribeSpotInstanceRequestsOutput{
SpotInstanceRequests: []*ec2.SpotInstanceRequest{
{InstanceId: aws.String("")},
},
},
},
},
},
asg: &autoScalingGroup{
Group: &autoscaling.Group{
Tags: []*autoscaling.TagDescription{},
},
name: "",
},
},
er: errors.New(""),
},
{
name: "with DescribeSpotInstanceRequestsOutput error",
req: spotInstanceRequest{
SpotInstanceRequest: &ec2.SpotInstanceRequest{
SpotInstanceRequestId: aws.String(""),
},
region: ®ion{
conf: &Config{},
services: connections{
ec2: mockEC2{
dsiro: &ec2.DescribeSpotInstanceRequestsOutput{
SpotInstanceRequests: []*ec2.SpotInstanceRequest{
{InstanceId: aws.String("")},
},
},
dsirerr: errors.New(""),
},
},
},
asg: &autoScalingGroup{
Group: &autoscaling.Group{
Tags: []*autoscaling.TagDescription{},
},
name: "",
},
},
er: errors.New(""),
},
}
for _, tc := range tests {
tc.req.waitForAndTagSpotInstance()
}
}
func Test_tag(t *testing.T) {
tests := []struct {
name string
tag string
req spotInstanceRequest
er error
}{
{
name: "with error",
tag: "tag",
req: spotInstanceRequest{
SpotInstanceRequest: &ec2.SpotInstanceRequest{
SpotInstanceRequestId: aws.String(""),
},
region: ®ion{
conf: &Config{},
services: connections{
ec2: mockEC2{
cterr: errors.New(""),
},
},
},
},
er: errors.New(""),
},
{
name: "without error",
tag: "tag",
req: spotInstanceRequest{
SpotInstanceRequest: &ec2.SpotInstanceRequest{
SpotInstanceRequestId: aws.String(""),
},
region: ®ion{
conf: &Config{},
services: connections{
ec2: mockEC2{
cterr: nil,
},
},
},
},
er: nil,
},
}
for _, tc := range tests {
er := tc.req.tag(tc.tag)
if er != nil && er.Error() != tc.er.Error() {
t.Errorf("error actual: %s, expected: %s", er.Error(), tc.er.Error())
}
}
}