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

Delta Between Two Patch Sets: state/relationunit_test.go

Issue 9738043: cmd/jujud: do not change password
Left Patch Set: Created 11 years, 10 months ago
Right Patch Set: cmd/jujud: do not change password Created 11 years, 9 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:
Right: Side by side diff | Download
« no previous file with change/comment | « state/relationunit.go ('k') | state/service.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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 state_test 4 package state_test
5 5
6 import ( 6 import (
7 . "launchpad.net/gocheck" 7 . "launchpad.net/gocheck"
8 "launchpad.net/juju-core/charm" 8 "launchpad.net/juju-core/charm"
9 "launchpad.net/juju-core/errors" 9 "launchpad.net/juju-core/errors"
10 "launchpad.net/juju-core/state" 10 "launchpad.net/juju-core/state"
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 c.Assert(err, IsNil) 335 c.Assert(err, IsNil)
336 err = pr.ru3.EnterScope(nil) 336 err = pr.ru3.EnterScope(nil)
337 c.Assert(err, Equals, state.ErrCannotEnterScope) 337 c.Assert(err, Equals, state.ErrCannotEnterScope)
338 } 338 }
339 339
340 func (s *RelationUnitSuite) TestPeerWatchScope(c *C) { 340 func (s *RelationUnitSuite) TestPeerWatchScope(c *C) {
341 pr := NewPeerRelation(c, &s.ConnSuite) 341 pr := NewPeerRelation(c, &s.ConnSuite)
342 342
343 // Test empty initial event. 343 // Test empty initial event.
344 w0 := pr.ru0.WatchScope() 344 w0 := pr.ru0.WatchScope()
345 » defer stop(c, w0) 345 » defer AssertStop(c, w0)
346 s.assertScopeChange(c, w0, nil, nil) 346 s.assertScopeChange(c, w0, nil, nil)
347 s.assertNoScopeChange(c, w0) 347 s.assertNoScopeChange(c, w0)
348 348
349 // ru0 enters; check no change, but settings written. 349 // ru0 enters; check no change, but settings written.
350 err := pr.ru0.EnterScope(map[string]interface{}{"foo": "bar"}) 350 err := pr.ru0.EnterScope(map[string]interface{}{"foo": "bar"})
351 c.Assert(err, IsNil) 351 c.Assert(err, IsNil)
352 s.assertNoScopeChange(c, w0) 352 s.assertNoScopeChange(c, w0)
353 node, err := pr.ru0.Settings() 353 node, err := pr.ru0.Settings()
354 c.Assert(err, IsNil) 354 c.Assert(err, IsNil)
355 c.Assert(node.Map(), DeepEquals, map[string]interface{}{"foo": "bar"}) 355 c.Assert(node.Map(), DeepEquals, map[string]interface{}{"foo": "bar"})
356 356
357 // ru1 enters; check change is observed. 357 // ru1 enters; check change is observed.
358 err = pr.ru1.EnterScope(nil) 358 err = pr.ru1.EnterScope(nil)
359 c.Assert(err, IsNil) 359 c.Assert(err, IsNil)
360 s.assertScopeChange(c, w0, []string{"riak/1"}, nil) 360 s.assertScopeChange(c, w0, []string{"riak/1"}, nil)
361 s.assertNoScopeChange(c, w0) 361 s.assertNoScopeChange(c, w0)
362 362
363 // ru1 enters again, check no problems and no changes. 363 // ru1 enters again, check no problems and no changes.
364 err = pr.ru1.EnterScope(nil) 364 err = pr.ru1.EnterScope(nil)
365 c.Assert(err, IsNil) 365 c.Assert(err, IsNil)
366 s.assertNoScopeChange(c, w0) 366 s.assertNoScopeChange(c, w0)
367 367
368 // Stop watching; ru2 enters. 368 // Stop watching; ru2 enters.
369 » stop(c, w0) 369 » AssertStop(c, w0)
370 err = pr.ru2.EnterScope(nil) 370 err = pr.ru2.EnterScope(nil)
371 c.Assert(err, IsNil) 371 c.Assert(err, IsNil)
372 372
373 // Start watch again, check initial event. 373 // Start watch again, check initial event.
374 w0 = pr.ru0.WatchScope() 374 w0 = pr.ru0.WatchScope()
375 » defer stop(c, w0) 375 » defer AssertStop(c, w0)
376 s.assertScopeChange(c, w0, []string{"riak/1", "riak/2"}, nil) 376 s.assertScopeChange(c, w0, []string{"riak/1", "riak/2"}, nil)
377 s.assertNoScopeChange(c, w0) 377 s.assertNoScopeChange(c, w0)
378 378
379 // ru1 leaves; check event. 379 // ru1 leaves; check event.
380 err = pr.ru1.LeaveScope() 380 err = pr.ru1.LeaveScope()
381 c.Assert(err, IsNil) 381 c.Assert(err, IsNil)
382 s.assertScopeChange(c, w0, nil, []string{"riak/1"}) 382 s.assertScopeChange(c, w0, nil, []string{"riak/1"})
383 s.assertNoScopeChange(c, w0) 383 s.assertNoScopeChange(c, w0)
384 384
385 // ru1 leaves again; check no problems and no changes. 385 // ru1 leaves again; check no problems and no changes.
386 err = pr.ru1.LeaveScope() 386 err = pr.ru1.LeaveScope()
387 c.Assert(err, IsNil) 387 c.Assert(err, IsNil)
388 s.assertNoScopeChange(c, w0) 388 s.assertNoScopeChange(c, w0)
389 } 389 }
390 390
391 func (s *RelationUnitSuite) TestProReqWatchScope(c *C) { 391 func (s *RelationUnitSuite) TestProReqWatchScope(c *C) {
392 prr := NewProReqRelation(c, &s.ConnSuite, charm.ScopeGlobal) 392 prr := NewProReqRelation(c, &s.ConnSuite, charm.ScopeGlobal)
393 393
394 // Test empty initial events for all RUs. 394 // Test empty initial events for all RUs.
395 ws := prr.watches() 395 ws := prr.watches()
396 for _, w := range ws { 396 for _, w := range ws {
397 » » defer stop(c, w) 397 » » defer AssertStop(c, w)
398 } 398 }
399 for _, w := range ws { 399 for _, w := range ws {
400 s.assertScopeChange(c, w, nil, nil) 400 s.assertScopeChange(c, w, nil, nil)
401 } 401 }
402 s.assertNoScopeChange(c, ws...) 402 s.assertNoScopeChange(c, ws...)
403 403
404 // pru0 enters; check detected only by req RUs. 404 // pru0 enters; check detected only by req RUs.
405 err := prr.pru0.EnterScope(nil) 405 err := prr.pru0.EnterScope(nil)
406 c.Assert(err, IsNil) 406 c.Assert(err, IsNil)
407 rws := func() []*state.RelationScopeWatcher { 407 rws := func() []*state.RelationScopeWatcher {
(...skipping 10 matching lines...) Expand all
418 pws := func() []*state.RelationScopeWatcher { 418 pws := func() []*state.RelationScopeWatcher {
419 return []*state.RelationScopeWatcher{ws[0], ws[1]} 419 return []*state.RelationScopeWatcher{ws[0], ws[1]}
420 } 420 }
421 for _, w := range pws() { 421 for _, w := range pws() {
422 s.assertScopeChange(c, w, []string{"wordpress/0"}, nil) 422 s.assertScopeChange(c, w, []string{"wordpress/0"}, nil)
423 } 423 }
424 s.assertNoScopeChange(c, ws...) 424 s.assertNoScopeChange(c, ws...)
425 425
426 // Stop watches; remaining RUs enter. 426 // Stop watches; remaining RUs enter.
427 for _, w := range ws { 427 for _, w := range ws {
428 » » stop(c, w) 428 » » AssertStop(c, w)
429 } 429 }
430 err = prr.pru1.EnterScope(nil) 430 err = prr.pru1.EnterScope(nil)
431 c.Assert(err, IsNil) 431 c.Assert(err, IsNil)
432 err = prr.rru1.EnterScope(nil) 432 err = prr.rru1.EnterScope(nil)
433 c.Assert(err, IsNil) 433 c.Assert(err, IsNil)
434 434
435 // Start new watches, check initial events. 435 // Start new watches, check initial events.
436 ws = prr.watches() 436 ws = prr.watches()
437 for _, w := range ws { 437 for _, w := range ws {
438 » » defer stop(c, w) 438 » » defer AssertStop(c, w)
439 } 439 }
440 for _, w := range pws() { 440 for _, w := range pws() {
441 s.assertScopeChange(c, w, []string{"wordpress/0", "wordpress/1"} , nil) 441 s.assertScopeChange(c, w, []string{"wordpress/0", "wordpress/1"} , nil)
442 } 442 }
443 for _, w := range rws() { 443 for _, w := range rws() {
444 s.assertScopeChange(c, w, []string{"mysql/0", "mysql/1"}, nil) 444 s.assertScopeChange(c, w, []string{"mysql/0", "mysql/1"}, nil)
445 } 445 }
446 s.assertNoScopeChange(c, ws...) 446 s.assertNoScopeChange(c, ws...)
447 447
448 // pru0 leaves; check detected only by req RUs. 448 // pru0 leaves; check detected only by req RUs.
(...skipping 12 matching lines...) Expand all
461 } 461 }
462 s.assertNoScopeChange(c, ws...) 462 s.assertNoScopeChange(c, ws...)
463 } 463 }
464 464
465 func (s *RelationUnitSuite) TestContainerWatchScope(c *C) { 465 func (s *RelationUnitSuite) TestContainerWatchScope(c *C) {
466 prr := NewProReqRelation(c, &s.ConnSuite, charm.ScopeContainer) 466 prr := NewProReqRelation(c, &s.ConnSuite, charm.ScopeContainer)
467 467
468 // Test empty initial events for all RUs. 468 // Test empty initial events for all RUs.
469 ws := prr.watches() 469 ws := prr.watches()
470 for _, w := range ws { 470 for _, w := range ws {
471 » » defer stop(c, w) 471 » » defer AssertStop(c, w)
472 } 472 }
473 for _, w := range ws { 473 for _, w := range ws {
474 s.assertScopeChange(c, w, nil, nil) 474 s.assertScopeChange(c, w, nil, nil)
475 } 475 }
476 s.assertNoScopeChange(c, ws...) 476 s.assertNoScopeChange(c, ws...)
477 477
478 // pru0 enters; check detected only by same-container req. 478 // pru0 enters; check detected only by same-container req.
479 err := prr.pru0.EnterScope(nil) 479 err := prr.pru0.EnterScope(nil)
480 c.Assert(err, IsNil) 480 c.Assert(err, IsNil)
481 s.assertScopeChange(c, ws[2], []string{"mysql/0"}, nil) 481 s.assertScopeChange(c, ws[2], []string{"mysql/0"}, nil)
482 s.assertNoScopeChange(c, ws...) 482 s.assertNoScopeChange(c, ws...)
483 483
484 // req1 enters; check detected only by same-container pro. 484 // req1 enters; check detected only by same-container pro.
485 err = prr.rru1.EnterScope(nil) 485 err = prr.rru1.EnterScope(nil)
486 c.Assert(err, IsNil) 486 c.Assert(err, IsNil)
487 s.assertScopeChange(c, ws[1], []string{"logging/1"}, nil) 487 s.assertScopeChange(c, ws[1], []string{"logging/1"}, nil)
488 s.assertNoScopeChange(c, ws...) 488 s.assertNoScopeChange(c, ws...)
489 489
490 // Stop watches; remaining RUs enter scope. 490 // Stop watches; remaining RUs enter scope.
491 for _, w := range ws { 491 for _, w := range ws {
492 » » stop(c, w) 492 » » AssertStop(c, w)
493 } 493 }
494 err = prr.pru1.EnterScope(nil) 494 err = prr.pru1.EnterScope(nil)
495 c.Assert(err, IsNil) 495 c.Assert(err, IsNil)
496 err = prr.rru0.EnterScope(nil) 496 err = prr.rru0.EnterScope(nil)
497 c.Assert(err, IsNil) 497 c.Assert(err, IsNil)
498 498
499 // Start new watches, check initial events. 499 // Start new watches, check initial events.
500 ws = prr.watches() 500 ws = prr.watches()
501 for _, w := range ws { 501 for _, w := range ws {
502 » » defer stop(c, w) 502 » » defer AssertStop(c, w)
503 } 503 }
504 s.assertScopeChange(c, ws[0], []string{"logging/0"}, nil) 504 s.assertScopeChange(c, ws[0], []string{"logging/0"}, nil)
505 s.assertScopeChange(c, ws[1], []string{"logging/1"}, nil) 505 s.assertScopeChange(c, ws[1], []string{"logging/1"}, nil)
506 s.assertScopeChange(c, ws[2], []string{"mysql/0"}, nil) 506 s.assertScopeChange(c, ws[2], []string{"mysql/0"}, nil)
507 s.assertScopeChange(c, ws[3], []string{"mysql/1"}, nil) 507 s.assertScopeChange(c, ws[3], []string{"mysql/1"}, nil)
508 s.assertNoScopeChange(c, ws...) 508 s.assertNoScopeChange(c, ws...)
509 509
510 // pru0 leaves; check detected only by same-container req. 510 // pru0 leaves; check detected only by same-container req.
511 err = prr.pru0.LeaveScope() 511 err = prr.pru0.LeaveScope()
512 c.Assert(err, IsNil) 512 c.Assert(err, IsNil)
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 break 639 break
640 } 640 }
641 } 641 }
642 if !found { 642 if !found {
643 u = unit 643 u = unit
644 break 644 break
645 } 645 }
646 } 646 }
647 c.Assert(u, NotNil) 647 c.Assert(u, NotNil)
648 } 648 }
649 preventUnitDestroyRemove(c, u)
649 ru, err := rel.Unit(u) 650 ru, err := rel.Unit(u)
650 c.Assert(err, IsNil) 651 c.Assert(err, IsNil)
651 return u, ru 652 return u, ru
652 } 653 }
653 654
654 type RUs []*state.RelationUnit 655 type RUs []*state.RelationUnit
655
656 type stopper interface {
657 Stop() error
658 }
659
660 func stop(c *C, s stopper) {
661 c.Assert(s.Stop(), IsNil)
662 }
LEFTRIGHT

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