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

Delta Between Two Patch Sets: state/internal_test.go

Issue 6200044: Added relations to topology. (Closed)
Left Patch Set: Added relations to topology. Created 12 years, 9 months ago
Right Patch Set: Added relations to topology. Created 12 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « [revision details] ('k') | state/relation.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
1 // launchpad.net/juju/go/state 1 // launchpad.net/juju/go/state
2 // 2 //
3 // Copyright (c) 2011-2012 Canonical Ltd. 3 // Copyright (c) 2011-2012 Canonical Ltd.
4 package state 4 package state
5 5
6 import ( 6 import (
7 . "launchpad.net/gocheck" 7 . "launchpad.net/gocheck"
8 "launchpad.net/goyaml" 8 "launchpad.net/goyaml"
9 "launchpad.net/gozk/zookeeper" 9 "launchpad.net/gozk/zookeeper"
10 ) 10 )
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 c.Assert(relation.Services[RolePeer], Equals, "s-p") 469 c.Assert(relation.Services[RolePeer], Equals, "s-p")
470 } 470 }
471 471
472 func (s *TopologySuite) TestAddRelation(c *C) { 472 func (s *TopologySuite) TestAddRelation(c *C) {
473 // Check that adding a relation works and can only be done once and with······· 473 // Check that adding a relation works and can only be done once and with·······
474 // valid services. 474 // valid services.
475 relation, err := s.t.Relation("r-1") 475 relation, err := s.t.Relation("r-1")
476 c.Assert(relation, IsNil) 476 c.Assert(relation, IsNil)
477 c.Assert(err, ErrorMatches, `relation "r-1" does not exist`) 477 c.Assert(err, ErrorMatches, `relation "r-1" does not exist`)
478 s.t.AddService("s-p", "mysql") 478 s.t.AddService("s-p", "mysql")
479 » s.t.AddService("s-c", "wordpress") 479 » s.t.AddService("s-r", "wordpress")
480 err = s.t.AddRelation("r-1", &zkRelation{ 480 err = s.t.AddRelation("r-1", &zkRelation{
481 Interface: "ifce", 481 Interface: "ifce",
482 Scope: ScopeGlobal, 482 Scope: ScopeGlobal,
483 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleCons umer: "s-c"}, 483 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleRequ irer: "s-r"},
484 }) 484 })
485 c.Assert(err, IsNil) 485 c.Assert(err, IsNil)
486 relation, err = s.t.Relation("r-1") 486 relation, err = s.t.Relation("r-1")
487 c.Assert(err, IsNil) 487 c.Assert(err, IsNil)
488 c.Assert(relation, NotNil) 488 c.Assert(relation, NotNil)
489 c.Assert(relation.Services[RoleProvider], Equals, "s-p") 489 c.Assert(relation.Services[RoleProvider], Equals, "s-p")
490 » c.Assert(relation.Services[RoleConsumer], Equals, "s-c") 490 » c.Assert(relation.Services[RoleRequirer], Equals, "s-r")
491 491
492 err = s.t.AddRelation("r-2", &zkRelation{ 492 err = s.t.AddRelation("r-2", &zkRelation{
493 Interface: "", 493 Interface: "",
494 Scope: ScopeGlobal, 494 Scope: ScopeGlobal,
495 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleCons umer: "s-c"}, 495 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleRequ irer: "s-r"},
496 }) 496 })
497 c.Assert(err, ErrorMatches, `relation interface is empty`) 497 c.Assert(err, ErrorMatches, `relation interface is empty`)
498 498
499 » err = s.t.AddRelation("r-2", &zkRelation{ 499 » err = s.t.AddRelation("r-3", &zkRelation{
500 Interface: "ifce", 500 Interface: "ifce",
501 Scope: ScopeGlobal, 501 Scope: ScopeGlobal,
502 Services: map[RelationRole]string{}, 502 Services: map[RelationRole]string{},
503 }) 503 })
504 » c.Assert(err, ErrorMatches, `no service defined`) 504 » c.Assert(err, ErrorMatches, `relation has no services`)
505 505
506 » err = s.t.AddRelation("r-2", &zkRelation{ 506 » err = s.t.AddRelation("r-4", &zkRelation{
507 Interface: "ifce", 507 Interface: "ifce",
508 Scope: ScopeGlobal, 508 Scope: ScopeGlobal,
509 Services: map[RelationRole]string{RoleProvider: "s-p"}, 509 Services: map[RelationRole]string{RoleProvider: "s-p"},
510 }) 510 })
511 » c.Assert(err, ErrorMatches, `provider or consumer service missing`) 511 » c.Assert(err, ErrorMatches, `relation has provider but no requirer`)
512 512
513 » err = s.t.AddRelation("r-2", &zkRelation{ 513 » err = s.t.AddRelation("r-5", &zkRelation{
514 » » Interface: "ifce", 514 » » Interface: "ifce",
515 » » Scope: ScopeGlobal, 515 » » Scope: ScopeGlobal,
516 » » Services: map[RelationRole]string{RoleProvider: "s-p", RolePeer : "s-c"}, 516 » » Services: map[RelationRole]string{RoleProvider: "s-p", RolePeer : "s-r"},
517 » }) 517 » })
518 » c.Assert(err, ErrorMatches, `mixed peer with provider or consumer servic e`) 518 » c.Assert(err, ErrorMatches, `relation has provider but no requirer`)
519 519
520 » err = s.t.AddRelation("r-2", &zkRelation{ 520 » err = s.t.AddRelation("r-6", &zkRelation{
521 » » Interface: "ifce", 521 » » Interface: "ifce",
522 » » Scope: ScopeGlobal, 522 » » Scope: ScopeGlobal,
523 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleCons umer: "s-c", RolePeer: "s-c"}, 523 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleRequ irer: "s-r", RolePeer: "s-r"},
524 » }) 524 » })
525 » c.Assert(err, ErrorMatches, `too much services defined`) 525 » c.Assert(err, ErrorMatches, `relation with mixed peer, provider, and req uirer roles`)
526 526
527 » err = s.t.AddRelation("r-2", &zkRelation{ 527 » err = s.t.AddRelation("r-7", &zkRelation{
528 » » Interface: "ifce", 528 » » Interface: "ifce",
529 » » Scope: ScopeGlobal, 529 » » Scope: ScopeGlobal,
530 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleCons umer: "illegal"}, 530 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleRequ irer: "illegal"},
531 }) 531 })
532 c.Assert(err, ErrorMatches, `service with key "illegal" not found`) 532 c.Assert(err, ErrorMatches, `service with key "illegal" not found`)
533 533
534 err = s.t.AddRelation("r-1", &zkRelation{ 534 err = s.t.AddRelation("r-1", &zkRelation{
535 Interface: "ifce", 535 Interface: "ifce",
536 Scope: ScopeGlobal, 536 Scope: ScopeGlobal,
537 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleCons umer: "s-c"}, 537 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleRequ irer: "s-r"},
538 }) 538 })
539 c.Assert(err, ErrorMatches, `relation key "r-1" already in use`) 539 c.Assert(err, ErrorMatches, `relation key "r-1" already in use`)
540 } 540 }
541 541
542 func (s *TopologySuite) TestRelationKeys(c *C) { 542 func (s *TopologySuite) TestRelationKeys(c *C) {
543 // Check that fetching the relation keys works. 543 // Check that fetching the relation keys works.
544 keys := s.t.RelationKeys() 544 keys := s.t.RelationKeys()
545 c.Assert(keys, DeepEquals, []string{}) 545 c.Assert(keys, DeepEquals, []string{})
546 546
547 s.t.AddService("s-p", "riak") 547 s.t.AddService("s-p", "riak")
548 s.t.AddRelation("r-1", &zkRelation{ 548 s.t.AddRelation("r-1", &zkRelation{
549 Interface: "ifce", 549 Interface: "ifce",
550 Scope: ScopeGlobal, 550 Scope: ScopeGlobal,
551 Services: map[RelationRole]string{RolePeer: "s-p"}, 551 Services: map[RelationRole]string{RolePeer: "s-p"},
552 }) 552 })
553 keys = s.t.RelationKeys() 553 keys = s.t.RelationKeys()
554 c.Assert(keys, DeepEquals, []string{"r-1"}) 554 c.Assert(keys, DeepEquals, []string{"r-1"})
555 555
556 s.t.AddRelation("r-2", &zkRelation{ 556 s.t.AddRelation("r-2", &zkRelation{
557 Interface: "ifce", 557 Interface: "ifce",
558 Scope: ScopeGlobal, 558 Scope: ScopeGlobal,
559 Services: map[RelationRole]string{RolePeer: "s-p"}, 559 Services: map[RelationRole]string{RolePeer: "s-p"},
560 }) 560 })
561 keys = s.t.RelationKeys() 561 keys = s.t.RelationKeys()
562 c.Assert(keys, DeepEquals, []string{"r-1", "r-2"}) 562 c.Assert(keys, DeepEquals, []string{"r-1", "r-2"})
563 } 563 }
564 564
565 func (s *TopologySuite) TestRelationsForService(c *C) {
566 // Check that fetching the relations for a service works.
567 s.t.AddService("s-p", "riak")
568 relations, err := s.t.RelationsForService("s-p")
569 c.Assert(err, IsNil)
570 c.Assert(relations, HasLen, 0)
571
572 s.t.AddRelation("r-0", &zkRelation{
573 Interface: "ifce0",
574 Scope: ScopeGlobal,
575 Services: map[RelationRole]string{RolePeer: "s-p"},
576 })
577 s.t.AddRelation("r-1", &zkRelation{
578 Interface: "ifce1",
579 Scope: ScopeGlobal,
580 Services: map[RelationRole]string{RolePeer: "s-p"},
581 })
582 relations, err = s.t.RelationsForService("s-p")
583 c.Assert(err, IsNil)
584 c.Assert(relations, HasLen, 2)
585 c.Assert(relations["r-0"].Interface, Equals, "ifce0")
586 c.Assert(relations["r-1"].Interface, Equals, "ifce1")
587
588 s.t.RemoveRelation("r-0")
589 relations, err = s.t.RelationsForService("s-p")
590 c.Assert(err, IsNil)
591 c.Assert(relations, HasLen, 1)
592 c.Assert(relations["r-1"].Interface, Equals, "ifce1")
593 }
594
565 func (s *TopologySuite) TestRemoveRelation(c *C) { 595 func (s *TopologySuite) TestRemoveRelation(c *C) {
566 // Check that removing of a relation works. 596 // Check that removing of a relation works.
567 s.t.AddService("s-c", "wordpress") 597 s.t.AddService("s-c", "wordpress")
568 s.t.AddService("s-p", "mysql") 598 s.t.AddService("s-p", "mysql")
569 599
570 err := s.t.AddRelation("r-1", &zkRelation{ 600 err := s.t.AddRelation("r-1", &zkRelation{
571 Interface: "ifce", 601 Interface: "ifce",
572 Scope: ScopeGlobal, 602 Scope: ScopeGlobal,
573 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleCons umer: "s-c"}, 603 » » Services: map[RelationRole]string{RoleProvider: "s-p", RoleRequ irer: "s-c"},
574 }) 604 })
575 c.Assert(err, IsNil) 605 c.Assert(err, IsNil)
576 606
577 relation, err := s.t.Relation("r-1") 607 relation, err := s.t.Relation("r-1")
578 c.Assert(err, IsNil) 608 c.Assert(err, IsNil)
579 c.Assert(relation, NotNil) 609 c.Assert(relation, NotNil)
580 c.Assert(relation.Services[RoleProvider], Equals, "s-p") 610 c.Assert(relation.Services[RoleProvider], Equals, "s-p")
581 » c.Assert(relation.Services[RoleConsumer], Equals, "s-c") 611 » c.Assert(relation.Services[RoleRequirer], Equals, "s-c")
582 612
583 s.t.RemoveRelation("r-1") 613 s.t.RemoveRelation("r-1")
584 614
585 relation, err = s.t.Relation("r-1") 615 relation, err = s.t.Relation("r-1")
586 c.Assert(relation, IsNil) 616 c.Assert(relation, IsNil)
587 c.Assert(err, ErrorMatches, `relation "r-1" does not exist`) 617 c.Assert(err, ErrorMatches, `relation "r-1" does not exist`)
588 } 618 }
589 619
590 func (s *TopologySuite) TestRemoveServiceWithRelations(c *C) { 620 func (s *TopologySuite) TestRemoveServiceWithRelations(c *C) {
591 // Check that the removing of a service with 621 // Check that the removing of a service with
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 out := Quote(in) 980 out := Quote(in)
951 c.Assert(out, Equals, in) 981 c.Assert(out, Equals, in)
952 } 982 }
953 983
954 func (s *QuoteSuite) TestQuote(c *C) { 984 func (s *QuoteSuite) TestQuote(c *C) {
955 // Check that invalid chars are translated correctly. 985 // Check that invalid chars are translated correctly.
956 in := "hello_there/how'are~you-today.sir" 986 in := "hello_there/how'are~you-today.sir"
957 out := Quote(in) 987 out := Quote(in)
958 c.Assert(out, Equals, "hello_5f_there_2f_how_27_are_7e_you-today.sir") 988 c.Assert(out, Equals, "hello_5f_there_2f_how_27_are_7e_you-today.sir")
959 } 989 }
LEFTRIGHT

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