OLD | NEW |
1 // launchpad.net/juju/go/state | |
2 // | |
3 // Copyright (c) 2011-2012 Canonical Ltd. | |
4 package state_test | 1 package state_test |
5 | 2 |
6 import ( | 3 import ( |
7 "fmt" | 4 "fmt" |
8 . "launchpad.net/gocheck" | 5 . "launchpad.net/gocheck" |
9 "launchpad.net/gozk/zookeeper" | 6 "launchpad.net/gozk/zookeeper" |
10 "launchpad.net/juju/go/charm" | 7 "launchpad.net/juju/go/charm" |
11 "launchpad.net/juju/go/state" | 8 "launchpad.net/juju/go/state" |
12 "launchpad.net/juju/go/testing" | 9 "launchpad.net/juju/go/testing" |
13 "net/url" | 10 "net/url" |
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 c.Assert(err, IsNil) | 1008 c.Assert(err, IsNil) |
1012 c.Assert(alive, Equals, true) | 1009 c.Assert(alive, Equals, true) |
1013 | 1010 |
1014 pinger.Kill() | 1011 pinger.Kill() |
1015 | 1012 |
1016 alive, err = unit.AgentAlive() | 1013 alive, err = unit.AgentAlive() |
1017 c.Assert(err, IsNil) | 1014 c.Assert(err, IsNil) |
1018 c.Assert(alive, Equals, false) | 1015 c.Assert(alive, Equals, false) |
1019 } | 1016 } |
1020 | 1017 |
| 1018 func (s *StateSuite) TestAddRelation(c *C) { |
| 1019 dummy := s.addDummyCharm(c) |
| 1020 // Provider and requirer. |
| 1021 s.st.AddService("mysqldb", dummy) |
| 1022 s.st.AddService("wordpress", dummy) |
| 1023 mysqlep := state.RelationEndpoint{"mysqldb", "blog", "db", state.RolePro
vider, state.ScopeGlobal} |
| 1024 blogep := state.RelationEndpoint{"wordpress", "blog", "db", state.RoleRe
quirer, state.ScopeGlobal} |
| 1025 relation, serviceRelations, err := s.st.AddRelation(blogep, mysqlep) |
| 1026 c.Assert(err, IsNil) |
| 1027 c.Assert(relation, NotNil) |
| 1028 c.Assert(serviceRelations, HasLen, 2) |
| 1029 c.Assert(serviceRelations[0].RelationScope(), Equals, state.ScopeGlobal) |
| 1030 c.Assert(serviceRelations[0].RelationRole(), Equals, state.RoleRequirer) |
| 1031 c.Assert(serviceRelations[1].RelationScope(), Equals, state.ScopeGlobal) |
| 1032 c.Assert(serviceRelations[1].RelationRole(), Equals, state.RoleProvider) |
| 1033 c.Assert(serviceRelations[0].RelationName(), Equals, serviceRelations[1]
.RelationName()) |
| 1034 // Peer. |
| 1035 s.st.AddService("riak", dummy) |
| 1036 riakep := state.RelationEndpoint{"riak", "ring", "cache", state.RolePeer
, state.ScopeGlobal} |
| 1037 relation, serviceRelations, err = s.st.AddRelation(riakep) |
| 1038 c.Assert(err, IsNil) |
| 1039 c.Assert(relation, NotNil) |
| 1040 c.Assert(serviceRelations, HasLen, 1) |
| 1041 c.Assert(serviceRelations[0].RelationScope(), Equals, state.ScopeGlobal) |
| 1042 c.Assert(serviceRelations[0].RelationRole(), Equals, state.RolePeer) |
| 1043 c.Assert(serviceRelations[0].RelationName(), Equals, "cache") |
| 1044 |
| 1045 } |
| 1046 |
| 1047 func (s *StateSuite) TestAddRelationMissingService(c *C) { |
| 1048 dummy := s.addDummyCharm(c) |
| 1049 s.st.AddService("mysqldb", dummy) |
| 1050 mysqlep := state.RelationEndpoint{"mysqldb", "blog", "db", state.RolePro
vider, state.ScopeGlobal} |
| 1051 blogep := state.RelationEndpoint{"wordpress", "blog", "db", state.RoleRe
quirer, state.ScopeGlobal} |
| 1052 _, _, err := s.st.AddRelation(blogep, mysqlep) |
| 1053 c.Assert(err, ErrorMatches, `service with name "wordpress" not found`) |
| 1054 } |
| 1055 |
| 1056 func (s *StateSuite) TestAddRelationMissingEndpoint(c *C) { |
| 1057 dummy := s.addDummyCharm(c) |
| 1058 s.st.AddService("mysqldb", dummy) |
| 1059 mysqlep := state.RelationEndpoint{"mysqldb", "blog", "db", state.RolePro
vider, state.ScopeGlobal} |
| 1060 _, _, err := s.st.AddRelation(mysqlep) |
| 1061 c.Assert(err, ErrorMatches, `can't add non-peer relation with a single s
ervice`) |
| 1062 } |
| 1063 |
| 1064 func (s *StateSuite) TestAddClientServerDifferentRoles(c *C) { |
| 1065 dummy := s.addDummyCharm(c) |
| 1066 s.st.AddService("mysqldb", dummy) |
| 1067 s.st.AddService("riak", dummy) |
| 1068 mysqlep := state.RelationEndpoint{"mysqldb", "ifce", "db", state.RoleReq
uirer, state.ScopeGlobal} |
| 1069 riakep := state.RelationEndpoint{"riak", "ring", "cache", state.RolePeer
, state.ScopeGlobal} |
| 1070 _, _, err := s.st.AddRelation(mysqlep, riakep) |
| 1071 c.Assert(err, ErrorMatches, `can't add relation between mysqldb:db and r
iak:cache`) |
| 1072 } |
| 1073 |
| 1074 func (s *StateSuite) TestAddRelationDifferentInterfaces(c *C) { |
| 1075 dummy := s.addDummyCharm(c) |
| 1076 s.st.AddService("mysqldb", dummy) |
| 1077 s.st.AddService("wordpress", dummy) |
| 1078 mysqlep := state.RelationEndpoint{"mysqldb", "ifce-a", "db", state.RoleP
rovider, state.ScopeGlobal} |
| 1079 blogep := state.RelationEndpoint{"wordpress", "ifce-b", "db", state.Role
Requirer, state.ScopeGlobal} |
| 1080 _, _, err := s.st.AddRelation(blogep, mysqlep) |
| 1081 c.Assert(err, ErrorMatches, `can't add relation between wordpress:db and
mysqldb:db`) |
| 1082 } |
| 1083 |
| 1084 func (s *StateSuite) TestAddClientServerRelationTwice(c *C) { |
| 1085 dummy := s.addDummyCharm(c) |
| 1086 // Provider and requirer. |
| 1087 s.st.AddService("mysqldb", dummy) |
| 1088 s.st.AddService("wordpress", dummy) |
| 1089 mysqlep := state.RelationEndpoint{"mysqldb", "blog", "db", state.RolePro
vider, state.ScopeGlobal} |
| 1090 blogep := state.RelationEndpoint{"wordpress", "blog", "db", state.RoleRe
quirer, state.ScopeGlobal} |
| 1091 _, _, err := s.st.AddRelation(blogep, mysqlep) |
| 1092 c.Assert(err, IsNil) |
| 1093 _, _, err = s.st.AddRelation(blogep, mysqlep) |
| 1094 c.Assert(err, ErrorMatches, `relation already exists`) |
| 1095 // Peer. |
| 1096 s.st.AddService("riak", dummy) |
| 1097 riakep := state.RelationEndpoint{"riak", "ring", "cache", state.RolePeer
, state.ScopeGlobal} |
| 1098 _, _, err = s.st.AddRelation(riakep) |
| 1099 c.Assert(err, IsNil) |
| 1100 _, _, err = s.st.AddRelation(riakep) |
| 1101 c.Assert(err, ErrorMatches, `relation already exists`) |
| 1102 } |
| 1103 |
| 1104 func (s *StateSuite) TestAddPeerRelationIllegalEndpointNumber(c *C) { |
| 1105 dummy := s.addDummyCharm(c) |
| 1106 s.st.AddService("mysqldb", dummy) |
| 1107 s.st.AddService("wordpress", dummy) |
| 1108 s.st.AddService("riak", dummy) |
| 1109 mysqlep := state.RelationEndpoint{"mysqldb", "ifce", "cache", state.Role
Provider, state.ScopeGlobal} |
| 1110 blogep := state.RelationEndpoint{"wordpress", "ifce", "cache", state.Rol
eRequirer, state.ScopeGlobal} |
| 1111 riakep := state.RelationEndpoint{"riak", "blog", "cache", state.RolePeer
, state.ScopeGlobal} |
| 1112 _, _, err := s.st.AddRelation() |
| 1113 c.Assert(err, ErrorMatches, `can't add relations between 0 services`) |
| 1114 _, _, err = s.st.AddRelation(mysqlep, blogep, riakep) |
| 1115 c.Assert(err, ErrorMatches, `can't add relations between 3 services`) |
| 1116 } |
| 1117 |
1021 func (s *StateSuite) TestEnvironment(c *C) { | 1118 func (s *StateSuite) TestEnvironment(c *C) { |
1022 path, err := s.zkConn.Create("/environment", "type: dummy\nname: foo\n",
0, zookeeper.WorldACL(zookeeper.PERM_ALL)) | 1119 path, err := s.zkConn.Create("/environment", "type: dummy\nname: foo\n",
0, zookeeper.WorldACL(zookeeper.PERM_ALL)) |
1023 c.Assert(err, IsNil) | 1120 c.Assert(err, IsNil) |
1024 c.Assert(path, Equals, "/environment") | 1121 c.Assert(path, Equals, "/environment") |
1025 | 1122 |
1026 env, err := s.st.Environment() | 1123 env, err := s.st.Environment() |
1027 env.Read() | 1124 env.Read() |
1028 c.Assert(err, IsNil) | 1125 c.Assert(err, IsNil) |
1029 c.Assert(env.Map(), DeepEquals, map[string]interface{}{"type": "dummy",
"name": "foo"}) | 1126 c.Assert(env.Map(), DeepEquals, map[string]interface{}{"type": "dummy",
"name": "foo"}) |
1030 } | 1127 } |
OLD | NEW |