~go-bot/juju-core/trunk

« back to all changes in this revision

Viewing changes to state/unit_test.go

  • Committer: Tarmac
  • Author(s): William Reade
  • Date: 2014-05-22 11:37:17 UTC
  • mfrom: (1679.1.11 juju-core)
  • Revision ID: tarmac-20140522113717-99dhnikcznpjpwrw
[r=fwereade],[bug=1192433] state: set departed on dying units' relations

This ended up including:

  * stopping using magic strings in cleanup
  * drawing a clear distinction between "joined" and "in scope" (which
    accounts for most of the lines of changes)

...but did *not* include:

  * fixing the name of the Uniter.JoinedRelations API, because I want to
    wait for API versioning

https://codereview.appspot.com/94540043/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1018
1018
        c.Assert(principal, gc.Equals, "")
1019
1019
}
1020
1020
 
1021
 
func (s *UnitSuite) TestJoinedRelations(c *gc.C) {
 
1021
func (s *UnitSuite) TestRelations(c *gc.C) {
1022
1022
        wordpress0 := s.unit
1023
1023
        mysql := s.AddTestingService(c, "mysql", s.AddTestingCharm(c, "mysql"))
1024
1024
        mysql0, err := mysql.AddUnit()
1028
1028
        rel, err := s.State.AddRelation(eps...)
1029
1029
        c.Assert(err, gc.IsNil)
1030
1030
 
1031
 
        assertJoinedRelations := func(unit *state.Unit, expect ...*state.Relation) {
1032
 
                actual, err := unit.JoinedRelations()
1033
 
                c.Assert(err, gc.IsNil)
 
1031
        assertEquals := func(actual, expect []*state.Relation) {
1034
1032
                c.Assert(actual, gc.HasLen, len(expect))
1035
1033
                for i, a := range actual {
1036
1034
                        c.Assert(a.Id(), gc.Equals, expect[i].Id())
1037
1035
                }
1038
1036
        }
1039
 
        assertJoinedRelations(wordpress0)
1040
 
        assertJoinedRelations(mysql0)
 
1037
        assertRelationsJoined := func(unit *state.Unit, expect ...*state.Relation) {
 
1038
                actual, err := unit.RelationsJoined()
 
1039
                c.Assert(err, gc.IsNil)
 
1040
                assertEquals(actual, expect)
 
1041
        }
 
1042
        assertRelationsInScope := func(unit *state.Unit, expect ...*state.Relation) {
 
1043
                actual, err := unit.RelationsInScope()
 
1044
                c.Assert(err, gc.IsNil)
 
1045
                assertEquals(actual, expect)
 
1046
        }
 
1047
        assertRelations := func(unit *state.Unit, expect ...*state.Relation) {
 
1048
                assertRelationsInScope(unit, expect...)
 
1049
                assertRelationsJoined(unit, expect...)
 
1050
        }
 
1051
        assertRelations(wordpress0)
 
1052
        assertRelations(mysql0)
1041
1053
 
1042
1054
        mysql0ru, err := rel.Unit(mysql0)
1043
1055
        c.Assert(err, gc.IsNil)
1044
1056
        err = mysql0ru.EnterScope(nil)
1045
1057
        c.Assert(err, gc.IsNil)
1046
 
        assertJoinedRelations(wordpress0)
1047
 
        assertJoinedRelations(mysql0, rel)
 
1058
        assertRelations(wordpress0)
 
1059
        assertRelations(mysql0, rel)
1048
1060
 
1049
1061
        wordpress0ru, err := rel.Unit(wordpress0)
1050
1062
        c.Assert(err, gc.IsNil)
1051
1063
        err = wordpress0ru.EnterScope(nil)
1052
1064
        c.Assert(err, gc.IsNil)
1053
 
        assertJoinedRelations(wordpress0, rel)
1054
 
        assertJoinedRelations(mysql0, rel)
 
1065
        assertRelations(wordpress0, rel)
 
1066
        assertRelations(mysql0, rel)
1055
1067
 
1056
 
        err = mysql0ru.LeaveScope()
 
1068
        err = mysql0ru.PrepareLeaveScope()
1057
1069
        c.Assert(err, gc.IsNil)
1058
 
        assertJoinedRelations(wordpress0, rel)
1059
 
        assertJoinedRelations(mysql0)
 
1070
        assertRelations(wordpress0, rel)
 
1071
        assertRelationsInScope(mysql0, rel)
 
1072
        assertRelationsJoined(mysql0)
1060
1073
}
1061
1074
 
1062
1075
func (s *UnitSuite) TestRemove(c *gc.C) {