4
. "launchpad.net/gocheck"
5
"launchpad.net/juju-core/constraints"
6
"launchpad.net/juju-core/testing"
9
type instanceTypeSuite struct {
13
var _ = Suite(&instanceTypeSuite{})
15
func (s *instanceTypeSuite) SetUpSuite(c *C) {
16
s.LoggingSuite.SetUpSuite(c)
17
UseTestInstanceTypeData(instanceTypeData)
20
func (s *instanceTypeSuite) TearDownSuite(c *C) {
21
UseTestInstanceTypeData(nil)
22
s.LoggingSuite.TearDownTest(c)
25
var instanceTypeData = map[string]uint64{
37
var getInstanceTypesTest = []struct {
47
"c1.medium", "m1.large", "m1.xlarge", "c1.xlarge", "cc1.4xlarge",
52
cons: "cpu-power=2000",
53
itypes: []string{"c1.xlarge", "cc1.4xlarge", "cc2.8xlarge"},
58
"m1.large", "m1.xlarge", "c1.xlarge", "cc1.4xlarge", "cc2.8xlarge",
61
info: "arches filtered by constraint",
63
itypes: []string{"m1.small", "m1.medium", "c1.medium"},
64
arches: []string{"i386"},
66
info: "t1.micro filtered out when no cpu-power set",
68
"m1.small", "m1.medium", "c1.medium", "m1.large", "m1.xlarge",
69
"c1.xlarge", "cc1.4xlarge", "cc2.8xlarge",
72
info: "t1.micro included when small cpu-power set",
75
"t1.micro", "m1.small", "m1.medium", "c1.medium", "m1.large",
76
"m1.xlarge", "c1.xlarge", "cc1.4xlarge", "cc2.8xlarge",
79
info: "t1.micro included when small cpu-power set 2",
80
cons: "cpu-power=1 arch=i386",
81
itypes: []string{"t1.micro", "m1.small", "m1.medium", "c1.medium"},
82
arches: []string{"i386"},
86
func (s *instanceTypeSuite) TestGetInstanceTypes(c *C) {
87
for i, t := range getInstanceTypesTest {
88
c.Logf("test %d: %s", i, t.info)
89
itypes, err := getInstanceTypes("test", constraints.MustParse(t.cons))
91
names := make([]string, len(itypes))
92
for i, itype := range itypes {
93
if len(t.arches) > 0 {
94
c.Check(itype.arches, DeepEquals, filterArches(itype.arches, t.arches))
96
c.Check(len(itype.arches) > 0, Equals, true)
100
c.Check(names, DeepEquals, t.itypes)
104
func (s *instanceTypeSuite) TestGetInstanceTypesErrors(c *C) {
105
_, err := getInstanceTypes("unknown-region", constraints.Value{})
106
c.Check(err, ErrorMatches, `no instance types found in unknown-region`)
108
cons := constraints.MustParse("cpu-power=9001")
109
_, err = getInstanceTypes("test", cons)
110
c.Check(err, ErrorMatches, `no instance types in test matching constraints "cpu-power=9001"`)
112
cons = constraints.MustParse("arch=i386 mem=8G")
113
_, err = getInstanceTypes("test", cons)
114
c.Check(err, ErrorMatches, `no instance types in test matching constraints "arch=i386 cpu-power=100 mem=8192M"`)
117
var instanceTypeMatchTests = []struct {
122
{"", "m1.small", both},
123
{"", "m1.large", amd64},
124
{"cpu-power=100", "m1.small", both},
125
{"arch=amd64", "m1.small", amd64},
126
{"cpu-cores=3", "m1.xlarge", amd64},
127
{"cpu-power=", "t1.micro", both},
128
{"cpu-power=500", "c1.medium", both},
129
{"cpu-power=2000", "c1.xlarge", amd64},
130
{"cpu-power=2001", "cc1.4xlarge", amd64},
131
{"mem=2G", "m1.medium", both},
133
{"arch=arm", "m1.small", nil},
134
{"cpu-power=100", "t1.micro", nil},
135
{"cpu-power=9001", "cc2.8xlarge", nil},
136
{"mem=1G", "t1.micro", nil},
137
{"arch=i386", "c1.xlarge", nil},
140
func (s *instanceTypeSuite) TestMatch(c *C) {
141
for i, t := range instanceTypeMatchTests {
143
cons := constraints.MustParse(t.cons)
144
var itype instanceType
145
for _, itype = range allInstanceTypes {
146
if itype.name == t.itype {
150
c.Assert(itype.name, Not(Equals), "")
151
itype, match := itype.match(cons)
152
if len(t.arches) > 0 {
153
c.Check(match, Equals, true)
155
expect.arches = t.arches
156
c.Check(itype, DeepEquals, expect)
158
c.Check(match, Equals, false)
159
c.Check(itype, DeepEquals, instanceType{})