~themue/juju-core/037-empty-strings-in-charm-config

« back to all changes in this revision

Viewing changes to environs/instances/image_test.go

  • Committer: Frank Mueller
  • Date: 2013-08-02 12:04:49 UTC
  • mfrom: (1567.1.18 juju-core)
  • Revision ID: frank.mueller@canonical.com-20130802120449-bdmjta1ppsgafwov
cmd/set: merged trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
package instances
5
5
 
6
6
import (
7
 
        . "launchpad.net/gocheck"
 
7
        gc "launchpad.net/gocheck"
 
8
 
 
9
        "testing"
 
10
 
8
11
        "launchpad.net/juju-core/constraints"
9
12
        "launchpad.net/juju-core/environs/imagemetadata"
10
13
        coretesting "launchpad.net/juju-core/testing"
11
 
        "testing"
12
14
)
13
15
 
14
16
type imageSuite struct {
16
18
}
17
19
 
18
20
func Test(t *testing.T) {
19
 
        TestingT(t)
 
21
        gc.TestingT(t)
20
22
}
21
23
 
22
 
var _ = Suite(&imageSuite{})
 
24
var _ = gc.Suite(&imageSuite{})
23
25
 
24
 
func (s *imageSuite) SetUpSuite(c *C) {
 
26
func (s *imageSuite) SetUpSuite(c *gc.C) {
25
27
        s.LoggingSuite.SetUpSuite(c)
26
28
}
27
29
 
28
 
func (s *imageSuite) TearDownSuite(c *C) {
 
30
func (s *imageSuite) TearDownSuite(c *gc.C) {
29
31
        s.LoggingSuite.TearDownTest(c)
30
32
}
31
33
 
190
192
        },
191
193
}
192
194
 
193
 
func (s *imageSuite) TestFindInstanceSpec(c *C) {
 
195
func (s *imageSuite) TestFindInstanceSpec(c *gc.C) {
194
196
        for _, t := range findInstanceSpecTests {
195
197
                c.Logf("test: %v", t.desc)
196
198
                t.init()
200
202
                        Arches:    t.arches,
201
203
                }
202
204
                imageMeta, err := imagemetadata.GetLatestImageIdMetadata([]byte(jsonImagesContent), &ic)
203
 
                c.Assert(err, IsNil)
 
205
                c.Assert(err, gc.IsNil)
204
206
                var images []Image
205
207
                for _, imageMetadata := range imageMeta {
206
208
                        im := *imageMetadata
217
219
                        Constraints: constraints.MustParse(t.constraints),
218
220
                }, t.instanceTypes)
219
221
                if t.err != "" {
220
 
                        c.Check(err, ErrorMatches, t.err)
221
 
                        continue
222
 
                }
223
 
                if !c.Check(err, IsNil) {
224
 
                        continue
225
 
                }
226
 
                c.Check(spec.Image.Id, Equals, t.imageId)
 
222
                        c.Check(err, gc.ErrorMatches, t.err)
 
223
                        continue
 
224
                }
 
225
                if !c.Check(err, gc.IsNil) {
 
226
                        continue
 
227
                }
 
228
                c.Check(spec.Image.Id, gc.Equals, t.imageId)
227
229
                if len(t.instanceTypes) == 1 {
228
 
                        c.Check(spec.InstanceType, DeepEquals, t.instanceTypes[0])
 
230
                        c.Check(spec.InstanceType, gc.DeepEquals, t.instanceTypes[0])
229
231
                }
230
232
        }
231
233
}
260
262
        },
261
263
}
262
264
 
263
 
func (s *imageSuite) TestImageMatch(c *C) {
 
265
func (s *imageSuite) TestImageMatch(c *gc.C) {
264
266
        for i, t := range imageMatchtests {
265
267
                c.Logf("test %d", i)
266
 
                c.Check(t.image.match(t.itype), Equals, t.match)
267
 
        }
 
268
                c.Check(t.image.match(t.itype), gc.Equals, t.match)
 
269
        }
 
270
}
 
271
 
 
272
func (*imageSuite) TestImageMetadataToImagesAcceptsNil(c *gc.C) {
 
273
        c.Check(ImageMetadataToImages(nil), gc.HasLen, 0)
 
274
}
 
275
 
 
276
func (*imageSuite) TestImageMetadataToImagesConvertsSelectMetadata(c *gc.C) {
 
277
        input := []*imagemetadata.ImageMetadata{
 
278
                {
 
279
                        Id:          "id",
 
280
                        Storage:     "storage-is-ignored",
 
281
                        VType:       "vtype",
 
282
                        Arch:        "arch",
 
283
                        RegionAlias: "region-alias-is-ignored",
 
284
                        RegionName:  "region-name-is-ignored",
 
285
                        Endpoint:    "endpoint-is-ignored",
 
286
                },
 
287
        }
 
288
        expectation := []Image{
 
289
                {
 
290
                        Id:    "id",
 
291
                        VType: "vtype",
 
292
                        Arch:  "arch",
 
293
                },
 
294
        }
 
295
        c.Check(ImageMetadataToImages(input), gc.DeepEquals, expectation)
 
296
}
 
297
 
 
298
func (*imageSuite) TestImageMetadataToImagesMaintainsOrdering(c *gc.C) {
 
299
        input := []*imagemetadata.ImageMetadata{
 
300
                {Id: "one", Arch: "Z80"},
 
301
                {Id: "two", Arch: "i386"},
 
302
                {Id: "three", Arch: "amd64"},
 
303
        }
 
304
        expectation := []Image{
 
305
                {Id: "one", Arch: "Z80"},
 
306
                {Id: "two", Arch: "i386"},
 
307
                {Id: "three", Arch: "amd64"},
 
308
        }
 
309
        c.Check(ImageMetadataToImages(input), gc.DeepEquals, expectation)
268
310
}