launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/provider/ec2/ec2_test.go (about) 1 // Copyright 2011, 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package ec2 5 6 import ( 7 amzec2 "launchpad.net/goamz/ec2" 8 gc "launchpad.net/gocheck" 9 10 "launchpad.net/juju-core/constraints" 11 ) 12 13 type Suite struct{} 14 15 var _ = gc.Suite(&Suite{}) 16 17 type RootDiskTest struct { 18 name string 19 constraint *uint64 20 disksize uint64 21 device amzec2.BlockDeviceMapping 22 } 23 24 var rootDiskTests = []RootDiskTest{ 25 { 26 "nil constraint", 27 nil, 28 8192, 29 amzec2.BlockDeviceMapping{VolumeSize: 8, DeviceName: "/dev/sda1"}, 30 }, 31 { 32 "too small constraint", 33 pInt(4000), 34 8192, 35 amzec2.BlockDeviceMapping{VolumeSize: 8, DeviceName: "/dev/sda1"}, 36 }, 37 { 38 "big constraint", 39 pInt(20 * 1024), 40 20 * 1024, 41 amzec2.BlockDeviceMapping{VolumeSize: 20, DeviceName: "/dev/sda1"}, 42 }, 43 { 44 "round up constraint", 45 pInt(20*1024 + 1), 46 21 * 1024, 47 amzec2.BlockDeviceMapping{VolumeSize: 21, DeviceName: "/dev/sda1"}, 48 }, 49 } 50 51 func (*Suite) TestRootDisk(c *gc.C) { 52 for _, t := range rootDiskTests { 53 c.Logf("Test %s", t.name) 54 cons := constraints.Value{RootDisk: t.constraint} 55 device, size := getDiskSize(cons) 56 c.Check(size, gc.Equals, t.disksize) 57 c.Check(device, gc.DeepEquals, t.device) 58 } 59 } 60 61 func pInt(i uint64) *uint64 { 62 return &i 63 }