@@ -6,7 +6,8 @@ package instances
6
6
import (
7
7
"sort"
8
8
9
- . "launchpad.net/gocheck"
9
+ gc "launchpad.net/gocheck"
10
+
10
11
"launchpad.net/juju-core/constraints"
11
12
"launchpad.net/juju-core/testing"
12
13
)
@@ -15,13 +16,13 @@ type instanceTypeSuite struct {
15
16
testing.LoggingSuite
16
17
}
17
18
18
- var _ = Suite (& instanceTypeSuite {})
19
+ var _ = gc . Suite (& instanceTypeSuite {})
19
20
20
- func (s * instanceTypeSuite ) SetUpSuite (c * C ) {
21
+ func (s * instanceTypeSuite ) SetUpSuite (c * gc. C ) {
21
22
s .LoggingSuite .SetUpSuite (c )
22
23
}
23
24
24
- func (s * instanceTypeSuite ) TearDownSuite (c * C ) {
25
+ func (s * instanceTypeSuite ) TearDownSuite (c * gc. C ) {
25
26
s .LoggingSuite .TearDownTest (c )
26
27
}
27
28
@@ -100,38 +101,38 @@ var instanceTypes = []InstanceType{
100
101
}
101
102
102
103
var getInstanceTypesTest = []struct {
103
- info string
104
+ about string
104
105
cons string
105
106
itypesToUse []InstanceType
106
107
expectedItypes []string
107
108
arches []string
108
109
}{
109
110
{
110
- info : "cpu-cores" ,
111
- cons : "cpu-cores=2" ,
111
+ about : "cpu-cores" ,
112
+ cons : "cpu-cores=2" ,
112
113
expectedItypes : []string {
113
114
"c1.medium" , "m1.large" , "m1.xlarge" , "c1.xlarge" , "cc1.4xlarge" ,
114
115
"cc2.8xlarge" ,
115
116
},
116
117
}, {
117
- info : "cpu-power" ,
118
+ about : "cpu-power" ,
118
119
cons : "cpu-power=2000" ,
119
120
expectedItypes : []string {"c1.xlarge" , "cc1.4xlarge" , "cc2.8xlarge" },
120
121
}, {
121
- info : "mem" ,
122
- cons : "mem=4G" ,
122
+ about : "mem" ,
123
+ cons : "mem=4G" ,
123
124
expectedItypes : []string {
124
125
"m1.large" , "m1.xlarge" , "c1.xlarge" , "cc1.4xlarge" , "cc2.8xlarge" ,
125
126
},
126
127
}, {
127
- info : "arches filtered by constraint" ,
128
+ about : "arches filtered by constraint" ,
128
129
cons : "cpu-power=100 arch=arm" ,
129
130
expectedItypes : []string {"m1.small" , "m1.medium" , "c1.medium" },
130
131
arches : []string {"arm" },
131
132
},
132
133
{
133
- info : "fallback instance type, enough memory for mongodb" ,
134
- cons : "mem=8G" ,
134
+ about : "fallback instance type, enough memory for mongodb" ,
135
+ cons : "mem=8G" ,
135
136
itypesToUse : []InstanceType {
136
137
{Id : "3" , Name : "it-3" , Arches : []string {"amd64" }, Mem : 4096 },
137
138
{Id : "2" , Name : "it-2" , Arches : []string {"amd64" }, Mem : 2048 },
@@ -140,8 +141,8 @@ var getInstanceTypesTest = []struct {
140
141
expectedItypes : []string {"it-2" },
141
142
},
142
143
{
143
- info : "fallback instance type, not enough memory for mongodb" ,
144
- cons : "mem=4G" ,
144
+ about : "fallback instance type, not enough memory for mongodb" ,
145
+ cons : "mem=4G" ,
145
146
itypesToUse : []InstanceType {
146
147
{Id : "2" , Name : "it-2" , Arches : []string {"amd64" }, Mem : 256 },
147
148
{Id : "1" , Name : "it-1" , Arches : []string {"amd64" }, Mem : 512 },
@@ -157,34 +158,34 @@ func constraint(region, cons string) *InstanceConstraint {
157
158
}
158
159
}
159
160
160
- func (s * instanceTypeSuite ) TestGetMatchingInstanceTypes (c * C ) {
161
+ func (s * instanceTypeSuite ) TestGetMatchingInstanceTypes (c * gc. C ) {
161
162
for i , t := range getInstanceTypesTest {
162
- c .Logf ("test %d: %s" , i , t .info )
163
+ c .Logf ("test %d: %s" , i , t .about )
163
164
itypesToUse := t .itypesToUse
164
165
if itypesToUse == nil {
165
166
itypesToUse = instanceTypes
166
167
}
167
168
itypes , err := getMatchingInstanceTypes (constraint ("test" , t .cons ), itypesToUse )
168
- c .Assert (err , IsNil )
169
+ c .Assert (err , gc . IsNil )
169
170
names := make ([]string , len (itypes ))
170
171
for i , itype := range itypes {
171
172
if len (t .arches ) > 0 {
172
- c .Check (itype .Arches , DeepEquals , filterArches (itype .Arches , t .arches ))
173
+ c .Check (itype .Arches , gc . DeepEquals , filterArches (itype .Arches , t .arches ))
173
174
} else {
174
- c .Check (len (itype .Arches ) > 0 , Equals , true )
175
+ c .Check (len (itype .Arches ) > 0 , gc . Equals , true )
175
176
}
176
177
names [i ] = itype .Name
177
178
}
178
- c .Check (names , DeepEquals , t .expectedItypes )
179
+ c .Check (names , gc . DeepEquals , t .expectedItypes )
179
180
}
180
181
}
181
182
182
- func (s * instanceTypeSuite ) TestGetMatchingInstanceTypesErrors (c * C ) {
183
+ func (s * instanceTypeSuite ) TestGetMatchingInstanceTypesErrors (c * gc. C ) {
183
184
_ , err := getMatchingInstanceTypes (constraint ("test" , "cpu-power=9001" ), nil )
184
- c .Check (err , ErrorMatches , `no instance types in test matching constraints "cpu-power=9001"` )
185
+ c .Check (err , gc . ErrorMatches , `no instance types in test matching constraints "cpu-power=9001"` )
185
186
186
187
_ , err = getMatchingInstanceTypes (constraint ("test" , "arch=i386 mem=8G" ), instanceTypes )
187
- c .Check (err , ErrorMatches , `no instance types in test matching constraints "arch=i386 mem=8192M"` )
188
+ c .Check (err , gc . ErrorMatches , `no instance types in test matching constraints "arch=i386 mem=8192M"` )
188
189
}
189
190
190
191
var instanceTypeMatchTests = []struct {
@@ -210,7 +211,7 @@ var instanceTypeMatchTests = []struct {
210
211
{"arch=arm" , "c1.xlarge" , nil },
211
212
}
212
213
213
- func (s * instanceTypeSuite ) TestMatch (c * C ) {
214
+ func (s * instanceTypeSuite ) TestMatch (c * gc. C ) {
214
215
for i , t := range instanceTypeMatchTests {
215
216
c .Logf ("test %d" , i )
216
217
cons := constraints .MustParse (t .cons )
@@ -220,27 +221,27 @@ func (s *instanceTypeSuite) TestMatch(c *C) {
220
221
break
221
222
}
222
223
}
223
- c .Assert (itype .Name , Not (Equals ), "" )
224
+ c .Assert (itype .Name , gc . Not (gc . Equals ), "" )
224
225
itype , match := itype .match (cons )
225
226
if len (t .arches ) > 0 {
226
- c .Check (match , Equals , true )
227
+ c .Check (match , gc . Equals , true )
227
228
expect := itype
228
229
expect .Arches = t .arches
229
- c .Check (itype , DeepEquals , expect )
230
+ c .Check (itype , gc . DeepEquals , expect )
230
231
} else {
231
- c .Check (match , Equals , false )
232
- c .Check (itype , DeepEquals , InstanceType {})
232
+ c .Check (match , gc . Equals , false )
233
+ c .Check (itype , gc . DeepEquals , InstanceType {})
233
234
}
234
235
}
235
236
}
236
237
237
- var byCostTest = []struct {
238
- info string
238
+ var byCostTests = []struct {
239
+ about string
239
240
itypesToUse []InstanceType
240
241
expectedItypes []string
241
242
}{
242
243
{
243
- info : "default to lowest cost" ,
244
+ about : "default to lowest cost" ,
244
245
itypesToUse : []InstanceType {
245
246
{Id : "2" , Name : "it-2" , CpuCores : 2 , Mem : 4096 , Cost : 240 },
246
247
{Id : "1" , Name : "it-1" , CpuCores : 1 , Mem : 2048 , Cost : 241 },
@@ -249,7 +250,7 @@ var byCostTest = []struct {
249
250
"it-2" , "it-1" ,
250
251
},
251
252
}, {
252
- info : "when no cost associated, pick lowest ram" ,
253
+ about : "when no cost associated, pick lowest ram" ,
253
254
itypesToUse : []InstanceType {
254
255
{Id : "2" , Name : "it-2" , CpuCores : 2 , Mem : 4096 },
255
256
{Id : "1" , Name : "it-1" , CpuCores : 1 , Mem : 2048 },
@@ -258,7 +259,7 @@ var byCostTest = []struct {
258
259
"it-1" , "it-2" ,
259
260
},
260
261
}, {
261
- info : "when cost is the same, pick lowest ram" ,
262
+ about : "when cost is the same, pick lowest ram" ,
262
263
itypesToUse : []InstanceType {
263
264
{Id : "2" , Name : "it-2" , CpuCores : 2 , Mem : 4096 , Cost : 240 },
264
265
{Id : "1" , Name : "it-1" , CpuCores : 1 , Mem : 2048 , Cost : 240 },
@@ -267,7 +268,7 @@ var byCostTest = []struct {
267
268
"it-1" , "it-2" ,
268
269
},
269
270
}, {
270
- info : "when cost and ram is the same, pick lowest cpu power" ,
271
+ about : "when cost and ram is the same, pick lowest cpu power" ,
271
272
itypesToUse : []InstanceType {
272
273
{Id : "2" , Name : "it-2" , CpuCores : 2 , CpuPower : CpuPower (200 )},
273
274
{Id : "1" , Name : "it-1" , CpuCores : 1 , CpuPower : CpuPower (100 )},
@@ -276,7 +277,7 @@ var byCostTest = []struct {
276
277
"it-1" , "it-2" ,
277
278
},
278
279
}, {
279
- info : "when cpu power is the same, pick the lowest cores" ,
280
+ about : "when cpu power is the same, pick the lowest cores" ,
280
281
itypesToUse : []InstanceType {
281
282
{Id : "2" , Name : "it-2" , CpuCores : 2 , CpuPower : CpuPower (200 )},
282
283
{Id : "1" , Name : "it-1" , CpuCores : 1 , CpuPower : CpuPower (200 )},
@@ -287,14 +288,14 @@ var byCostTest = []struct {
287
288
},
288
289
}
289
290
290
- func (s * instanceTypeSuite ) TestSortByCost (c * C ) {
291
- for i , t := range byCostTest {
292
- c .Logf ("test %d: %s" , i , t .info )
291
+ func (s * instanceTypeSuite ) TestSortByCost (c * gc. C ) {
292
+ for i , t := range byCostTests {
293
+ c .Logf ("test %d: %s" , i , t .about )
293
294
sort .Sort (byCost (t .itypesToUse ))
294
295
names := make ([]string , len (t .itypesToUse ))
295
296
for i , itype := range t .itypesToUse {
296
297
names [i ] = itype .Name
297
298
}
298
- c .Check (names , DeepEquals , t .expectedItypes )
299
+ c .Check (names , gc . DeepEquals , t .expectedItypes )
299
300
}
300
301
}
0 commit comments