-
Notifications
You must be signed in to change notification settings - Fork 25
/
ec2_instance_data_test.go
118 lines (110 loc) · 2.83 KB
/
ec2_instance_data_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
package ec2instancesinfo
import "testing"
func TestData(t *testing.T) {
tests := []struct {
name string
instance jsonInstance
wantErr bool
}{
{
name: "Parsing t2.nano memory, price, and ebs surcharge",
instance: jsonInstance{
InstanceType: "t2.nano",
Memory: 0.5,
VCPU: 1,
Pricing: map[string]RegionPrices{
"us-east-1": {
Linux: Pricing{
OnDemand: 0.0058,
},
MSWin: Pricing{
OnDemand: 0.0081,
},
EBSSurcharge: 0.0,
},
},
},
wantErr: false,
},
{
name: "Parsing m3.2xlarge memory, price, and ebs surcharge",
instance: jsonInstance{
InstanceType: "m3.2xlarge",
Memory: 30.0,
VCPU: 8,
Pricing: map[string]RegionPrices{
"us-east-1": {
Linux: Pricing{
OnDemand: 0.532,
},
MSWin: Pricing{
OnDemand: 1.036,
},
EBSSurcharge: 0.0,
},
},
},
wantErr: false,
},
{
name: "Parsing p2.16xlarge memory, price, GPUs and EBS surcharge",
instance: jsonInstance{
InstanceType: "p2.16xlarge",
Memory: 732.0,
VCPU: 64,
GPU: 16,
Pricing: map[string]RegionPrices{
"us-east-1": {
Linux: Pricing{
OnDemand: 14.4,
},
MSWin: Pricing{
OnDemand: 17.344,
},
EBSSurcharge: 0,
},
},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Data()
if (err != nil) != tt.wantErr {
t.Errorf("Data() error = %v, wantErr %v", err, tt.wantErr)
}
for _, i := range *got {
if i.InstanceType != tt.instance.InstanceType {
continue
}
if i.Memory != tt.instance.Memory {
t.Errorf("Data(): %v, want memory %v, got %v",
tt.instance.InstanceType, tt.instance.Memory, i.Memory)
}
if i.VCPU != tt.instance.VCPU {
t.Errorf("Data(): %v, want CPUs %v, got %v",
tt.instance.InstanceType, tt.instance.VCPU, i.VCPU)
}
if i.Pricing["us-east-1"].Linux.OnDemand != tt.instance.Pricing["us-east-1"].Linux.OnDemand {
t.Errorf("Data(): %v, want price %v, got %v",
tt.instance.InstanceType,
tt.instance.Pricing["us-east-1"].Linux.OnDemand,
i.Pricing["us-east-1"].Linux.OnDemand)
}
if i.Pricing["us-east-1"].MSWin.OnDemand != tt.instance.Pricing["us-east-1"].MSWin.OnDemand {
t.Errorf("Data(): %v, want MSWin price %v, got %v",
tt.instance.InstanceType,
tt.instance.Pricing["us-east-1"].MSWin.OnDemand,
i.Pricing["us-east-1"].MSWin.OnDemand)
}
if i.Pricing["us-east-1"].EBSSurcharge != tt.instance.Pricing["us-east-1"].EBSSurcharge {
t.Errorf("Data(): %v, want ebs cost %v, got %v",
tt.instance.InstanceType,
tt.instance.Pricing["us-east-1"].EBSSurcharge,
i.Pricing["us-east-1"].EBSSurcharge)
}
}
})
}
}