Skip to content

Commit d468a37

Browse files
author
Sidnei da Silva
committed
- Address review comments
1 parent 1d2f485 commit d468a37

File tree

1 file changed

+42
-41
lines changed

1 file changed

+42
-41
lines changed

environs/instances/instancetype_test.go

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ package instances
66
import (
77
"sort"
88

9-
. "launchpad.net/gocheck"
9+
gc "launchpad.net/gocheck"
10+
1011
"launchpad.net/juju-core/constraints"
1112
"launchpad.net/juju-core/testing"
1213
)
@@ -15,13 +16,13 @@ type instanceTypeSuite struct {
1516
testing.LoggingSuite
1617
}
1718

18-
var _ = Suite(&instanceTypeSuite{})
19+
var _ = gc.Suite(&instanceTypeSuite{})
1920

20-
func (s *instanceTypeSuite) SetUpSuite(c *C) {
21+
func (s *instanceTypeSuite) SetUpSuite(c *gc.C) {
2122
s.LoggingSuite.SetUpSuite(c)
2223
}
2324

24-
func (s *instanceTypeSuite) TearDownSuite(c *C) {
25+
func (s *instanceTypeSuite) TearDownSuite(c *gc.C) {
2526
s.LoggingSuite.TearDownTest(c)
2627
}
2728

@@ -100,38 +101,38 @@ var instanceTypes = []InstanceType{
100101
}
101102

102103
var getInstanceTypesTest = []struct {
103-
info string
104+
about string
104105
cons string
105106
itypesToUse []InstanceType
106107
expectedItypes []string
107108
arches []string
108109
}{
109110
{
110-
info: "cpu-cores",
111-
cons: "cpu-cores=2",
111+
about: "cpu-cores",
112+
cons: "cpu-cores=2",
112113
expectedItypes: []string{
113114
"c1.medium", "m1.large", "m1.xlarge", "c1.xlarge", "cc1.4xlarge",
114115
"cc2.8xlarge",
115116
},
116117
}, {
117-
info: "cpu-power",
118+
about: "cpu-power",
118119
cons: "cpu-power=2000",
119120
expectedItypes: []string{"c1.xlarge", "cc1.4xlarge", "cc2.8xlarge"},
120121
}, {
121-
info: "mem",
122-
cons: "mem=4G",
122+
about: "mem",
123+
cons: "mem=4G",
123124
expectedItypes: []string{
124125
"m1.large", "m1.xlarge", "c1.xlarge", "cc1.4xlarge", "cc2.8xlarge",
125126
},
126127
}, {
127-
info: "arches filtered by constraint",
128+
about: "arches filtered by constraint",
128129
cons: "cpu-power=100 arch=arm",
129130
expectedItypes: []string{"m1.small", "m1.medium", "c1.medium"},
130131
arches: []string{"arm"},
131132
},
132133
{
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",
135136
itypesToUse: []InstanceType{
136137
{Id: "3", Name: "it-3", Arches: []string{"amd64"}, Mem: 4096},
137138
{Id: "2", Name: "it-2", Arches: []string{"amd64"}, Mem: 2048},
@@ -140,8 +141,8 @@ var getInstanceTypesTest = []struct {
140141
expectedItypes: []string{"it-2"},
141142
},
142143
{
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",
145146
itypesToUse: []InstanceType{
146147
{Id: "2", Name: "it-2", Arches: []string{"amd64"}, Mem: 256},
147148
{Id: "1", Name: "it-1", Arches: []string{"amd64"}, Mem: 512},
@@ -157,34 +158,34 @@ func constraint(region, cons string) *InstanceConstraint {
157158
}
158159
}
159160

160-
func (s *instanceTypeSuite) TestGetMatchingInstanceTypes(c *C) {
161+
func (s *instanceTypeSuite) TestGetMatchingInstanceTypes(c *gc.C) {
161162
for i, t := range getInstanceTypesTest {
162-
c.Logf("test %d: %s", i, t.info)
163+
c.Logf("test %d: %s", i, t.about)
163164
itypesToUse := t.itypesToUse
164165
if itypesToUse == nil {
165166
itypesToUse = instanceTypes
166167
}
167168
itypes, err := getMatchingInstanceTypes(constraint("test", t.cons), itypesToUse)
168-
c.Assert(err, IsNil)
169+
c.Assert(err, gc.IsNil)
169170
names := make([]string, len(itypes))
170171
for i, itype := range itypes {
171172
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))
173174
} else {
174-
c.Check(len(itype.Arches) > 0, Equals, true)
175+
c.Check(len(itype.Arches) > 0, gc.Equals, true)
175176
}
176177
names[i] = itype.Name
177178
}
178-
c.Check(names, DeepEquals, t.expectedItypes)
179+
c.Check(names, gc.DeepEquals, t.expectedItypes)
179180
}
180181
}
181182

182-
func (s *instanceTypeSuite) TestGetMatchingInstanceTypesErrors(c *C) {
183+
func (s *instanceTypeSuite) TestGetMatchingInstanceTypesErrors(c *gc.C) {
183184
_, 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"`)
185186

186187
_, 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"`)
188189
}
189190

190191
var instanceTypeMatchTests = []struct {
@@ -210,7 +211,7 @@ var instanceTypeMatchTests = []struct {
210211
{"arch=arm", "c1.xlarge", nil},
211212
}
212213

213-
func (s *instanceTypeSuite) TestMatch(c *C) {
214+
func (s *instanceTypeSuite) TestMatch(c *gc.C) {
214215
for i, t := range instanceTypeMatchTests {
215216
c.Logf("test %d", i)
216217
cons := constraints.MustParse(t.cons)
@@ -220,27 +221,27 @@ func (s *instanceTypeSuite) TestMatch(c *C) {
220221
break
221222
}
222223
}
223-
c.Assert(itype.Name, Not(Equals), "")
224+
c.Assert(itype.Name, gc.Not(gc.Equals), "")
224225
itype, match := itype.match(cons)
225226
if len(t.arches) > 0 {
226-
c.Check(match, Equals, true)
227+
c.Check(match, gc.Equals, true)
227228
expect := itype
228229
expect.Arches = t.arches
229-
c.Check(itype, DeepEquals, expect)
230+
c.Check(itype, gc.DeepEquals, expect)
230231
} 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{})
233234
}
234235
}
235236
}
236237

237-
var byCostTest = []struct {
238-
info string
238+
var byCostTests = []struct {
239+
about string
239240
itypesToUse []InstanceType
240241
expectedItypes []string
241242
}{
242243
{
243-
info: "default to lowest cost",
244+
about: "default to lowest cost",
244245
itypesToUse: []InstanceType{
245246
{Id: "2", Name: "it-2", CpuCores: 2, Mem: 4096, Cost: 240},
246247
{Id: "1", Name: "it-1", CpuCores: 1, Mem: 2048, Cost: 241},
@@ -249,7 +250,7 @@ var byCostTest = []struct {
249250
"it-2", "it-1",
250251
},
251252
}, {
252-
info: "when no cost associated, pick lowest ram",
253+
about: "when no cost associated, pick lowest ram",
253254
itypesToUse: []InstanceType{
254255
{Id: "2", Name: "it-2", CpuCores: 2, Mem: 4096},
255256
{Id: "1", Name: "it-1", CpuCores: 1, Mem: 2048},
@@ -258,7 +259,7 @@ var byCostTest = []struct {
258259
"it-1", "it-2",
259260
},
260261
}, {
261-
info: "when cost is the same, pick lowest ram",
262+
about: "when cost is the same, pick lowest ram",
262263
itypesToUse: []InstanceType{
263264
{Id: "2", Name: "it-2", CpuCores: 2, Mem: 4096, Cost: 240},
264265
{Id: "1", Name: "it-1", CpuCores: 1, Mem: 2048, Cost: 240},
@@ -267,7 +268,7 @@ var byCostTest = []struct {
267268
"it-1", "it-2",
268269
},
269270
}, {
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",
271272
itypesToUse: []InstanceType{
272273
{Id: "2", Name: "it-2", CpuCores: 2, CpuPower: CpuPower(200)},
273274
{Id: "1", Name: "it-1", CpuCores: 1, CpuPower: CpuPower(100)},
@@ -276,7 +277,7 @@ var byCostTest = []struct {
276277
"it-1", "it-2",
277278
},
278279
}, {
279-
info: "when cpu power is the same, pick the lowest cores",
280+
about: "when cpu power is the same, pick the lowest cores",
280281
itypesToUse: []InstanceType{
281282
{Id: "2", Name: "it-2", CpuCores: 2, CpuPower: CpuPower(200)},
282283
{Id: "1", Name: "it-1", CpuCores: 1, CpuPower: CpuPower(200)},
@@ -287,14 +288,14 @@ var byCostTest = []struct {
287288
},
288289
}
289290

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)
293294
sort.Sort(byCost(t.itypesToUse))
294295
names := make([]string, len(t.itypesToUse))
295296
for i, itype := range t.itypesToUse {
296297
names[i] = itype.Name
297298
}
298-
c.Check(names, DeepEquals, t.expectedItypes)
299+
c.Check(names, gc.DeepEquals, t.expectedItypes)
299300
}
300301
}

0 commit comments

Comments
 (0)