Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Side by Side Diff: constraints/constraints_test.go

Issue 12859043: Add an os-disk constraint
Patch Set: Add an os-disk constraint Created 11 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 Canonical Ltd. 1 // Copyright 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package constraints_test 4 package constraints_test
5 5
6 import ( 6 import (
7 "encoding/json" 7 "encoding/json"
8 "testing" 8 "testing"
9 9
10 . "launchpad.net/gocheck" 10 . "launchpad.net/gocheck"
dimitern 2013/08/14 17:08:59 While you're at it can you import gocheck as gc an
sidnei.da.silva 2013/08/14 17:17:18 Done.
11 "launchpad.net/goyaml" 11 "launchpad.net/goyaml"
12 12
13 "launchpad.net/juju-core/constraints" 13 "launchpad.net/juju-core/constraints"
14 "launchpad.net/juju-core/instance" 14 "launchpad.net/juju-core/instance"
15 ) 15 )
16 16
17 func TestPackage(t *testing.T) { 17 func TestPackage(t *testing.T) {
18 TestingT(t) 18 TestingT(t)
19 } 19 }
20 20
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 }, { 199 }, {
200 summary: "double set mem together", 200 summary: "double set mem together",
201 args: []string{"mem=1G mem=2G"}, 201 args: []string{"mem=1G mem=2G"},
202 err: `bad "mem" constraint: already set`, 202 err: `bad "mem" constraint: already set`,
203 }, { 203 }, {
204 summary: "double set mem separately", 204 summary: "double set mem separately",
205 args: []string{"mem=1G", "mem=2G"}, 205 args: []string{"mem=1G", "mem=2G"},
206 err: `bad "mem" constraint: already set`, 206 err: `bad "mem" constraint: already set`,
207 }, 207 },
208 208
209 // "os-disk" in detail.
210 {
211 summary: "set os-disk empty",
212 args: []string{"os-disk="},
213 }, {
214 summary: "set os-disk zero",
215 args: []string{"os-disk=0"},
216 }, {
217 summary: "set os-disk without suffix",
218 args: []string{"os-disk=512"},
219 }, {
220 summary: "set os-disk with M suffix",
221 args: []string{"os-disk=512M"},
222 }, {
223 summary: "set os-disk with G suffix",
224 args: []string{"os-disk=1.5G"},
225 }, {
226 summary: "set os-disk with T suffix",
227 args: []string{"os-disk=36.2T"},
228 }, {
229 summary: "set os-disk with P suffix",
230 args: []string{"os-disk=18.9P"},
231 }, {
232 summary: "set nonsense os-disk 1",
233 args: []string{"os-disk=cheese"},
234 err: `bad "os-disk" constraint: must be a non-negative float with optional M/G/T/P suffix`,
235 }, {
236 summary: "set nonsense os-disk 2",
237 args: []string{"os-disk=-1"},
238 err: `bad "os-disk" constraint: must be a non-negative float with optional M/G/T/P suffix`,
239 }, {
240 summary: "set nonsense os-disk 3",
241 args: []string{"os-disk=32Y"},
242 err: `bad "os-disk" constraint: must be a non-negative float with optional M/G/T/P suffix`,
243 }, {
244 summary: "double set os-disk together",
245 args: []string{"os-disk=1G os-disk=2G"},
246 err: `bad "os-disk" constraint: already set`,
247 }, {
248 summary: "double set os-disk separately",
249 args: []string{"os-disk=1G", "os-disk=2G"},
250 err: `bad "os-disk" constraint: already set`,
251 },
252
209 // Everything at once. 253 // Everything at once.
210 { 254 {
211 summary: "kitchen sink together", 255 summary: "kitchen sink together",
212 » » args: []string{" mem=2T arch=i386 cpu-cores=4096 cpu-power= 9001 container=lxc"}, 256 » » args: []string{" os-disk=8G mem=2T arch=i386 cpu-cores=4096 cpu-power=9001 container=lxc"},
213 }, { 257 }, {
214 summary: "kitchen sink separately", 258 summary: "kitchen sink separately",
215 » » args: []string{"mem=2T", "cpu-cores=4096", "cpu-power=9001", "arch=arm", "container=lxc"}, 259 » » args: []string{"os-disk=8G", "mem=2T", "cpu-cores=4096", "cpu -power=9001", "arch=arm", "container=lxc"},
216 }, 260 },
217 } 261 }
218 262
219 func (s *ConstraintsSuite) TestParseConstraints(c *C) { 263 func (s *ConstraintsSuite) TestParseConstraints(c *C) {
220 for i, t := range parseConstraintsTests { 264 for i, t := range parseConstraintsTests {
221 c.Logf("test %d: %s", i, t.summary) 265 c.Logf("test %d: %s", i, t.summary)
222 cons0, err := constraints.Parse(t.args...) 266 cons0, err := constraints.Parse(t.args...)
223 if t.err == "" { 267 if t.err == "" {
224 c.Assert(err, IsNil) 268 c.Assert(err, IsNil)
225 } else { 269 } else {
(...skipping 24 matching lines...) Expand all
250 {Arch: strp("")}, 294 {Arch: strp("")},
251 {Arch: strp("amd64")}, 295 {Arch: strp("amd64")},
252 {Container: ctypep("")}, 296 {Container: ctypep("")},
253 {Container: ctypep("lxc")}, 297 {Container: ctypep("lxc")},
254 {CpuCores: uint64p(0)}, 298 {CpuCores: uint64p(0)},
255 {CpuCores: uint64p(128)}, 299 {CpuCores: uint64p(128)},
256 {CpuPower: uint64p(0)}, 300 {CpuPower: uint64p(0)},
257 {CpuPower: uint64p(250)}, 301 {CpuPower: uint64p(250)},
258 {Mem: uint64p(0)}, 302 {Mem: uint64p(0)},
259 {Mem: uint64p(98765)}, 303 {Mem: uint64p(98765)},
304 {OsDisk: uint64p(98765)},
dimitern 2013/08/14 17:08:59 Perhaps both: {OsDisk: uint64p(0)}, {OsDisk: uint6
sidnei.da.silva 2013/08/14 17:17:18 Done.
260 { 305 {
261 Arch: strp("i386"), 306 Arch: strp("i386"),
262 Container: ctypep("lxc"), 307 Container: ctypep("lxc"),
263 CpuCores: uint64p(4096), 308 CpuCores: uint64p(4096),
264 CpuPower: uint64p(9001), 309 CpuPower: uint64p(9001),
265 Mem: uint64p(18000000000), 310 Mem: uint64p(18000000000),
311 OsDisk: uint64p(18000000000),
266 }, 312 },
267 } 313 }
268 314
269 func (s *ConstraintsSuite) TestRoundtripGnuflagValue(c *C) { 315 func (s *ConstraintsSuite) TestRoundtripGnuflagValue(c *C) {
270 for i, t := range constraintsRoundtripTests { 316 for i, t := range constraintsRoundtripTests {
271 c.Logf("test %d", i) 317 c.Logf("test %d", i)
272 var cons constraints.Value 318 var cons constraints.Value
273 val := constraints.ConstraintsValue{&cons} 319 val := constraints.ConstraintsValue{&cons}
274 err := val.Set(t.String()) 320 err := val.Set(t.String())
275 c.Assert(err, IsNil) 321 c.Assert(err, IsNil)
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 }, { 419 }, {
374 desc: "mem with ignored fallback", 420 desc: "mem with ignored fallback",
375 initial: "mem=4G", 421 initial: "mem=4G",
376 fallbacks: "mem=8G", 422 fallbacks: "mem=8G",
377 final: "mem=4G", 423 final: "mem=4G",
378 }, { 424 }, {
379 desc: "mem from fallback", 425 desc: "mem from fallback",
380 fallbacks: "mem=8G", 426 fallbacks: "mem=8G",
381 final: "mem=8G", 427 final: "mem=8G",
382 }, { 428 }, {
429 desc: "os-disk with empty fallback",
430 initial: "os-disk=4G",
431 final: "os-disk=4G",
432 }, {
433 desc: "os-disk with ignored fallback",
434 initial: "os-disk=4G",
435 fallbacks: "os-disk=8G",
436 final: "os-disk=4G",
437 }, {
438 desc: "os-disk from fallback",
439 fallbacks: "os-disk=8G",
440 final: "os-disk=8G",
441 }, {
383 desc: "non-overlapping mix", 442 desc: "non-overlapping mix",
384 » » initial: "mem=4G arch=amd64", 443 » » initial: "os-disk=8G mem=4G arch=amd64",
385 fallbacks: "cpu-power=1000 cpu-cores=4", 444 fallbacks: "cpu-power=1000 cpu-cores=4",
386 » » final: "mem=4G arch=amd64 cpu-power=1000 cpu-cores=4", 445 » » final: "os-disk=8G mem=4G arch=amd64 cpu-power=1000 cpu-core s=4",
387 }, { 446 }, {
388 desc: "overlapping mix", 447 desc: "overlapping mix",
389 » » initial: "mem=4G arch=amd64", 448 » » initial: "os-disk=8G mem=4G arch=amd64",
390 fallbacks: "cpu-power=1000 cpu-cores=4 mem=8G", 449 fallbacks: "cpu-power=1000 cpu-cores=4 mem=8G",
391 » » final: "mem=4G arch=amd64 cpu-power=1000 cpu-cores=4", 450 » » final: "os-disk=8G mem=4G arch=amd64 cpu-power=1000 cpu-core s=4",
392 }, 451 },
393 } 452 }
394 453
395 func (s *ConstraintsSuite) TestWithFallbacks(c *C) { 454 func (s *ConstraintsSuite) TestWithFallbacks(c *C) {
396 for i, t := range withFallbacksTests { 455 for i, t := range withFallbacksTests {
397 c.Logf("test %d", i) 456 c.Logf("test %d", i)
398 initial := constraints.MustParse(t.initial) 457 initial := constraints.MustParse(t.initial)
399 fallbacks := constraints.MustParse(t.fallbacks) 458 fallbacks := constraints.MustParse(t.fallbacks)
400 final := constraints.MustParse(t.final) 459 final := constraints.MustParse(t.final)
401 c.Assert(initial.WithFallbacks(fallbacks), DeepEquals, final) 460 c.Assert(initial.WithFallbacks(fallbacks), DeepEquals, final)
(...skipping 15 matching lines...) Expand all
417 }, 476 },
418 } 477 }
419 478
420 func (s *ConstraintsSuite) TestHasContainer(c *C) { 479 func (s *ConstraintsSuite) TestHasContainer(c *C) {
421 for i, t := range hasContainerTests { 480 for i, t := range hasContainerTests {
422 c.Logf("test %d", i) 481 c.Logf("test %d", i)
423 cons := constraints.MustParse(t.constraints) 482 cons := constraints.MustParse(t.constraints)
424 c.Assert(cons.HasContainer(), Equals, t.hasContainer) 483 c.Assert(cons.HasContainer(), Equals, t.hasContainer)
425 } 484 }
426 } 485 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b