Left: | ||
Right: |
OLD | NEW |
---|---|
1 package main | 1 package main |
2 | 2 |
3 import ( | 3 import ( |
4 "bytes" | 4 "bytes" |
5 "encoding/json" | 5 "encoding/json" |
6 "fmt" | 6 "fmt" |
7 . "launchpad.net/gocheck" | 7 . "launchpad.net/gocheck" |
8 "launchpad.net/goyaml" | 8 "launchpad.net/goyaml" |
9 "launchpad.net/juju-core/charm" | 9 "launchpad.net/juju-core/charm" |
10 "launchpad.net/juju-core/cmd" | 10 "launchpad.net/juju-core/cmd" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 } | 28 } |
29 | 29 |
30 type StatusSuite struct { | 30 type StatusSuite struct { |
31 testing.JujuConnSuite | 31 testing.JujuConnSuite |
32 } | 32 } |
33 | 33 |
34 var _ = Suite(&StatusSuite{}) | 34 var _ = Suite(&StatusSuite{}) |
35 | 35 |
36 type M map[string]interface{} | 36 type M map[string]interface{} |
37 | 37 |
38 type L []interface{} | |
39 | |
38 type testCase struct { | 40 type testCase struct { |
39 summary string | 41 summary string |
40 steps []stepper | 42 steps []stepper |
41 } | 43 } |
42 | 44 |
43 func test(summary string, steps ...stepper) testCase { | 45 func test(summary string, steps ...stepper) testCase { |
44 return testCase{summary, steps} | 46 return testCase{summary, steps} |
45 } | 47 } |
46 | 48 |
47 type stepper interface { | 49 type stepper interface { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 machine1 = M{ | 92 machine1 = M{ |
91 "agent-state": "started", | 93 "agent-state": "started", |
92 "dns-name": "dummyenv-1.dns", | 94 "dns-name": "dummyenv-1.dns", |
93 "instance-id": "dummyenv-1", | 95 "instance-id": "dummyenv-1", |
94 } | 96 } |
95 machine2 = M{ | 97 machine2 = M{ |
96 "agent-state": "started", | 98 "agent-state": "started", |
97 "dns-name": "dummyenv-2.dns", | 99 "dns-name": "dummyenv-2.dns", |
98 "instance-id": "dummyenv-2", | 100 "instance-id": "dummyenv-2", |
99 } | 101 } |
102 machine3 = M{ | |
103 "agent-state": "started", | |
104 "dns-name": "dummyenv-3.dns", | |
105 "instance-id": "dummyenv-3", | |
106 } | |
100 unexposedService = M{ | 107 unexposedService = M{ |
101 "charm": "local:series/dummy-1", | 108 "charm": "local:series/dummy-1", |
102 "exposed": false, | 109 "exposed": false, |
103 } | 110 } |
104 exposedService = M{ | 111 exposedService = M{ |
105 "charm": "local:series/dummy-1", | 112 "charm": "local:series/dummy-1", |
106 "exposed": true, | 113 "exposed": true, |
107 } | 114 } |
108 ) | 115 ) |
109 | 116 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 }, | 199 }, |
193 }, | 200 }, |
194 "services": M{}, | 201 "services": M{}, |
195 }, | 202 }, |
196 }, | 203 }, |
197 ), test( | 204 ), test( |
198 "add two services and expose one, then add 2 more machines and s ome units", | 205 "add two services and expose one, then add 2 more machines and s ome units", |
199 addMachine{"0", state.JobManageEnviron}, | 206 addMachine{"0", state.JobManageEnviron}, |
200 startAliveMachine{"0"}, | 207 startAliveMachine{"0"}, |
201 setMachineStatus{"0", params.StatusStarted, ""}, | 208 setMachineStatus{"0", params.StatusStarted, ""}, |
202 » » addCharm{"dummy"}, | 209 » » addCharm{"dummy", nil, nil}, |
203 addService{"dummy-service", "dummy"}, | 210 addService{"dummy-service", "dummy"}, |
204 addService{"exposed-service", "dummy"}, | 211 addService{"exposed-service", "dummy"}, |
205 expect{ | 212 expect{ |
206 "no services exposed yet", | 213 "no services exposed yet", |
207 M{ | 214 M{ |
208 "machines": M{ | 215 "machines": M{ |
209 "0": machine0, | 216 "0": machine0, |
210 }, | 217 }, |
211 "services": M{ | 218 "services": M{ |
212 "dummy-service": unexposedService, | 219 "dummy-service": unexposedService, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 "dummy-service/0": M{ | 343 "dummy-service/0": M{ |
337 "machine": "1", | 344 "machine": "1", |
338 "agent-state": "down", | 345 "agent-state": "down", |
339 "agent-state-inf o": "(started)", | 346 "agent-state-inf o": "(started)", |
340 }, | 347 }, |
341 }, | 348 }, |
342 }, | 349 }, |
343 }, | 350 }, |
344 }, | 351 }, |
345 }, | 352 }, |
353 ), test( | |
354 "add two services, expose them, add machines and relate them", | |
355 addMachine{"0", state.JobManageEnviron}, | |
356 startAliveMachine{"0"}, | |
357 setMachineStatus{"0", params.StatusStarted, ""}, | |
358 addCharm{"dummy", | |
359 map[string]charm.Relation{ | |
360 "foo": charm.Relation{ | |
361 Name: "foo", | |
362 Role: charm.RoleProvider, | |
363 Interface: "ifce-a", | |
364 Optional: false, | |
365 Limit: 1, | |
366 Scope: charm.ScopeGlobal, | |
367 }, | |
368 "bar": charm.Relation{ | |
369 Name: "bar", | |
370 Role: charm.RoleProvider, | |
371 Interface: "ifce-b", | |
372 Optional: false, | |
373 Limit: 1, | |
374 Scope: charm.ScopeGlobal, | |
375 }, | |
376 }, | |
377 map[string]charm.Relation{ | |
378 "baz": charm.Relation{ | |
379 Name: "baz", | |
380 Role: charm.RoleRequirer, | |
381 Interface: "ifce-a", | |
382 Optional: false, | |
383 Limit: 1, | |
384 Scope: charm.ScopeGlobal, | |
385 }, | |
386 "yadda": charm.Relation{ | |
387 Name: "yadda", | |
388 Role: charm.RoleRequirer, | |
389 Interface: "ifce-b", | |
390 Optional: false, | |
391 Limit: 1, | |
392 Scope: charm.ScopeGlobal, | |
393 }, | |
394 }, | |
395 }, | |
396 | |
397 addService{"a-service", "dummy"}, | |
fwereade
2013/04/15 00:36:30
"mysql", "mysql"
TheMue
2013/04/15 12:20:41
Done.
| |
398 setServiceExposed{"a-service", true}, | |
399 addMachine{"1", state.JobHostUnits}, | |
400 startAliveMachine{"1"}, | |
401 setMachineStatus{"1", params.StatusStarted, ""}, | |
402 addUnit{"a-service", "1"}, | |
403 | |
404 addService{"b-service", "dummy"}, | |
fwereade
2013/04/15 00:36:30
"wordpress", "wordpress"
TheMue
2013/04/15 12:20:41
Done.
| |
405 setServiceExposed{"b-service", true}, | |
406 addMachine{"2", state.JobHostUnits}, | |
407 startAliveMachine{"2"}, | |
408 setMachineStatus{"2", params.StatusStarted, ""}, | |
409 addUnit{"b-service", "2"}, | |
410 | |
411 addService{"c-service", "dummy"}, | |
fwereade
2013/04/15 00:36:30
"another-wordpress", "wordpress"
...or whatever.
TheMue
2013/04/15 12:20:41
Done. But also "dummy" isn't very meaningful. ;)
| |
412 setServiceExposed{"c-service", true}, | |
413 addMachine{"3", state.JobHostUnits}, | |
414 startAliveMachine{"3"}, | |
415 setMachineStatus{"3", params.StatusStarted, ""}, | |
416 addUnit{"c-service", "3"}, | |
417 | |
418 relateServices{"a-service", "foo", "b-service", "baz", "ifce-a"} , | |
419 relateServices{"a-service", "bar", "c-service", "yadda", "ifce-b "}, | |
420 | |
421 expect{ | |
422 "two services with a provider requirer relation between them", | |
423 M{ | |
424 "machines": M{ | |
425 "0": machine0, | |
426 "1": machine1, | |
427 "2": machine2, | |
428 "3": machine3, | |
429 }, | |
430 "services": M{ | |
431 "a-service": M{ | |
432 "charm": "local:series/dummy-1 ", | |
433 "exposed": true, | |
434 "units": M{ | |
435 "a-service/0": M{ | |
436 "machine": " 1", | |
437 "agent-state": " pending", | |
438 }, | |
439 }, | |
440 "relations": M{ | |
441 "0": L{"b-service"}, | |
fwereade
2013/04/15 00:36:30
The key should be the relation name from the point
| |
442 "1": L{"c-service"}, | |
443 }, | |
444 }, | |
445 "b-service": M{ | |
446 "charm": "local:series/dummy-1 ", | |
447 "exposed": true, | |
448 "units": M{ | |
449 "b-service/0": M{ | |
450 "machine": " 2", | |
451 "agent-state": " pending", | |
452 }, | |
453 }, | |
454 "relations": M{ | |
455 "0": L{"a-service"}, | |
456 }, | |
457 }, | |
458 "c-service": M{ | |
459 "charm": "local:series/dummy-1 ", | |
460 "exposed": true, | |
461 "units": M{ | |
462 "c-service/0": M{ | |
463 "machine": " 3", | |
464 "agent-state": " pending", | |
465 }, | |
466 }, | |
467 "relations": M{ | |
468 "1": L{"a-service"}, | |
469 }, | |
470 }, | |
471 }, | |
472 }, | |
473 }, | |
346 ), | 474 ), |
347 } | 475 } |
348 | 476 |
349 // TODO(dfc) test failing components by destructively mutating the state under t he hood | 477 // TODO(dfc) test failing components by destructively mutating the state under t he hood |
350 | 478 |
351 type addMachine struct { | 479 type addMachine struct { |
352 machineId string | 480 machineId string |
353 job state.MachineJob | 481 job state.MachineJob |
354 } | 482 } |
355 | 483 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 } | 526 } |
399 | 527 |
400 func (st setTools) step(c *C, ctx *context) { | 528 func (st setTools) step(c *C, ctx *context) { |
401 m, err := ctx.st.Machine(st.machineId) | 529 m, err := ctx.st.Machine(st.machineId) |
402 c.Assert(err, IsNil) | 530 c.Assert(err, IsNil) |
403 err = m.SetAgentTools(st.tools) | 531 err = m.SetAgentTools(st.tools) |
404 c.Assert(err, IsNil) | 532 c.Assert(err, IsNil) |
405 } | 533 } |
406 | 534 |
407 type addCharm struct { | 535 type addCharm struct { |
408 » name string | 536 » name string |
537 » provides map[string]charm.Relation | |
538 » requires map[string]charm.Relation | |
fwereade
2013/04/15 00:36:30
Please just use the standard testing charms (wordp
TheMue
2013/04/15 12:20:41
Done.
TheMue
2013/04/15 12:20:41
Done.
| |
409 } | 539 } |
410 | 540 |
411 func (ac addCharm) step(c *C, ctx *context) { | 541 func (ac addCharm) step(c *C, ctx *context) { |
412 ch := coretesting.Charms.Dir(ac.name) | 542 ch := coretesting.Charms.Dir(ac.name) |
413 name, rev := ch.Meta().Name, ch.Revision() | 543 name, rev := ch.Meta().Name, ch.Revision() |
544 if ac.provides != nil { | |
545 ch.Meta().Provides = ac.provides | |
546 } | |
547 if ac.requires != nil { | |
548 ch.Meta().Requires = ac.requires | |
549 } | |
414 curl := charm.MustParseURL(fmt.Sprintf("local:series/%s-%d", name, rev)) | 550 curl := charm.MustParseURL(fmt.Sprintf("local:series/%s-%d", name, rev)) |
415 bundleURL, err := url.Parse(fmt.Sprintf("http://bundles.example.com/%s-% d", name, rev)) | 551 bundleURL, err := url.Parse(fmt.Sprintf("http://bundles.example.com/%s-% d", name, rev)) |
416 c.Assert(err, IsNil) | 552 c.Assert(err, IsNil) |
417 dummy, err := ctx.st.AddCharm(ch, curl, bundleURL, fmt.Sprintf("%s-%d-sh a256", name, rev)) | 553 dummy, err := ctx.st.AddCharm(ch, curl, bundleURL, fmt.Sprintf("%s-%d-sh a256", name, rev)) |
418 c.Assert(err, IsNil) | 554 c.Assert(err, IsNil) |
419 ctx.charms[ac.name] = dummy | 555 ctx.charms[ac.name] = dummy |
420 } | 556 } |
421 | 557 |
422 type addService struct { | 558 type addService struct { |
423 name string | 559 name string |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 status params.Status | 639 status params.Status |
504 statusInfo string | 640 statusInfo string |
505 } | 641 } |
506 | 642 |
507 func (sms setMachineStatus) step(c *C, ctx *context) { | 643 func (sms setMachineStatus) step(c *C, ctx *context) { |
508 m, err := ctx.st.Machine(sms.machineId) | 644 m, err := ctx.st.Machine(sms.machineId) |
509 err = m.SetStatus(sms.status, sms.statusInfo) | 645 err = m.SetStatus(sms.status, sms.statusInfo) |
510 c.Assert(err, IsNil) | 646 c.Assert(err, IsNil) |
511 } | 647 } |
512 | 648 |
649 type relateServices struct { | |
650 serviceNameA string | |
651 nameA string | |
652 serviceNameB string | |
653 nameB string | |
654 ifce string | |
655 } | |
656 | |
657 func (rs relateServices) step(c *C, ctx *context) { | |
658 epA := state.Endpoint{ | |
659 ServiceName: rs.serviceNameA, | |
660 Relation: charm.Relation{ | |
661 Interface: rs.ifce, | |
662 Name: rs.nameA, | |
663 Role: charm.RoleProvider, | |
664 Scope: charm.ScopeGlobal, | |
665 }, | |
666 } | |
667 epB := state.Endpoint{ | |
668 ServiceName: rs.serviceNameB, | |
669 Relation: charm.Relation{ | |
670 Interface: rs.ifce, | |
671 Name: rs.nameB, | |
672 Role: charm.RoleRequirer, | |
673 Scope: charm.ScopeGlobal, | |
674 }, | |
675 } | |
676 _, err := ctx.st.AddRelation(epA, epB) | |
677 c.Assert(err, IsNil) | |
678 } | |
fwereade
2013/04/15 00:36:30
type relateServices struct{
ep1, ep2 string
}
TheMue
2013/04/15 12:20:41
Done.
| |
679 | |
513 type expect struct { | 680 type expect struct { |
514 what string | 681 what string |
515 output M | 682 output M |
516 } | 683 } |
517 | 684 |
518 func (e expect) step(c *C, ctx *context) { | 685 func (e expect) step(c *C, ctx *context) { |
519 c.Log("expect: %s", e.what) | 686 c.Log("expect: %s", e.what) |
520 | 687 |
521 // Now execute the command for each format. | 688 // Now execute the command for each format. |
522 for _, format := range statusFormats { | 689 for _, format := range statusFormats { |
(...skipping 22 matching lines...) Expand all Loading... | |
545 for i, t := range statusTests { | 712 for i, t := range statusTests { |
546 c.Log("test %d: %s", i, t.summary) | 713 c.Log("test %d: %s", i, t.summary) |
547 func() { | 714 func() { |
548 // Prepare context and run all steps to setup. | 715 // Prepare context and run all steps to setup. |
549 ctx := s.newContext() | 716 ctx := s.newContext() |
550 defer s.resetContext(c, ctx) | 717 defer s.resetContext(c, ctx) |
551 ctx.run(c, t.steps) | 718 ctx.run(c, t.steps) |
552 }() | 719 }() |
553 } | 720 } |
554 } | 721 } |
OLD | NEW |