OLD | NEW |
1 package server_test | 1 package jujuc_test |
2 | 2 |
3 import ( | 3 import ( |
4 "fmt" | 4 "fmt" |
5 . "launchpad.net/gocheck" | 5 . "launchpad.net/gocheck" |
6 "launchpad.net/juju-core/charm" | 6 "launchpad.net/juju-core/charm" |
7 "launchpad.net/juju-core/cmd" | 7 "launchpad.net/juju-core/cmd" |
8 "launchpad.net/juju-core/cmd/jujuc/server" | |
9 "launchpad.net/juju-core/juju/testing" | 8 "launchpad.net/juju-core/juju/testing" |
10 "launchpad.net/juju-core/state" | 9 "launchpad.net/juju-core/state" |
| 10 "launchpad.net/juju-core/worker/uniter/jujuc" |
11 ) | 11 ) |
12 | 12 |
13 type RelationIdsSuite struct { | 13 type RelationIdsSuite struct { |
14 testing.JujuConnSuite | 14 testing.JujuConnSuite |
15 ch *state.Charm | 15 ch *state.Charm |
16 service *state.Service | 16 service *state.Service |
17 unit *state.Unit | 17 unit *state.Unit |
18 » relctxs map[int]*server.RelationContext | 18 » relctxs map[int]*jujuc.RelationContext |
19 } | 19 } |
20 | 20 |
21 var _ = Suite(&RelationIdsSuite{}) | 21 var _ = Suite(&RelationIdsSuite{}) |
22 | 22 |
23 func (s *RelationIdsSuite) SetUpTest(c *C) { | 23 func (s *RelationIdsSuite) SetUpTest(c *C) { |
24 s.JujuConnSuite.SetUpTest(c) | 24 s.JujuConnSuite.SetUpTest(c) |
25 s.ch = s.AddTestingCharm(c, "dummy") | 25 s.ch = s.AddTestingCharm(c, "dummy") |
26 var err error | 26 var err error |
27 s.service, err = s.State.AddService("main", s.ch) | 27 s.service, err = s.State.AddService("main", s.ch) |
28 c.Assert(err, IsNil) | 28 c.Assert(err, IsNil) |
29 s.unit, err = s.service.AddUnit() | 29 s.unit, err = s.service.AddUnit() |
30 c.Assert(err, IsNil) | 30 c.Assert(err, IsNil) |
31 » s.relctxs = map[int]*server.RelationContext{} | 31 » s.relctxs = map[int]*jujuc.RelationContext{} |
32 s.AddRelatedServices(c, "x", 3) | 32 s.AddRelatedServices(c, "x", 3) |
33 s.AddRelatedServices(c, "y", 1) | 33 s.AddRelatedServices(c, "y", 1) |
34 } | 34 } |
35 | 35 |
36 func (s *RelationIdsSuite) AddRelatedServices(c *C, relname string, count int) { | 36 func (s *RelationIdsSuite) AddRelatedServices(c *C, relname string, count int) { |
37 mainep := state.RelationEndpoint{ | 37 mainep := state.RelationEndpoint{ |
38 "main", "ifce", relname, state.RoleProvider, charm.ScopeGlobal, | 38 "main", "ifce", relname, state.RoleProvider, charm.ScopeGlobal, |
39 } | 39 } |
40 for i := 0; i < count; i++ { | 40 for i := 0; i < count; i++ { |
41 service, err := s.State.AddService(fmt.Sprintf("%s%d", relname,
i), s.ch) | 41 service, err := s.State.AddService(fmt.Sprintf("%s%d", relname,
i), s.ch) |
42 c.Assert(err, IsNil) | 42 c.Assert(err, IsNil) |
43 otherep := state.RelationEndpoint{ | 43 otherep := state.RelationEndpoint{ |
44 service.Name(), "ifce", relname, state.RoleRequirer, cha
rm.ScopeGlobal, | 44 service.Name(), "ifce", relname, state.RoleRequirer, cha
rm.ScopeGlobal, |
45 } | 45 } |
46 rel, err := s.State.AddRelation(mainep, otherep) | 46 rel, err := s.State.AddRelation(mainep, otherep) |
47 c.Assert(err, IsNil) | 47 c.Assert(err, IsNil) |
48 ru, err := rel.Unit(s.unit) | 48 ru, err := rel.Unit(s.unit) |
49 c.Assert(err, IsNil) | 49 c.Assert(err, IsNil) |
50 » » s.relctxs[rel.Id()] = server.NewRelationContext(ru, nil) | 50 » » s.relctxs[rel.Id()] = jujuc.NewRelationContext(ru, nil) |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 func (s *RelationIdsSuite) GetHookContext(c *C, relid int) *server.HookContext { | 54 func (s *RelationIdsSuite) GetHookContext(c *C, relid int) *jujuc.HookContext { |
55 if relid != -1 { | 55 if relid != -1 { |
56 _, found := s.relctxs[relid] | 56 _, found := s.relctxs[relid] |
57 c.Assert(found, Equals, true) | 57 c.Assert(found, Equals, true) |
58 } | 58 } |
59 » return &server.HookContext{ | 59 » return &jujuc.HookContext{ |
60 Service: s.service, | 60 Service: s.service, |
61 Unit: s.unit, | 61 Unit: s.unit, |
62 Id: "TestCtx", | 62 Id: "TestCtx", |
63 RelationId: relid, | 63 RelationId: relid, |
64 RemoteUnitName: "", | 64 RemoteUnitName: "", |
65 Relations: s.relctxs, | 65 Relations: s.relctxs, |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 var relationIdsTests = []struct { | 69 var relationIdsTests = []struct { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 com, err := hctx.NewCommand("relation-ids") | 181 com, err := hctx.NewCommand("relation-ids") |
182 c.Assert(err, IsNil) | 182 c.Assert(err, IsNil) |
183 ctx := dummyContext(c) | 183 ctx := dummyContext(c) |
184 code := cmd.Main(com, ctx, []string{"--help"}) | 184 code := cmd.Main(com, ctx, []string{"--help"}) |
185 c.Assert(code, Equals, 0) | 185 c.Assert(code, Equals, 0) |
186 c.Assert(bufferString(ctx.Stdout), Equals, "") | 186 c.Assert(bufferString(ctx.Stdout), Equals, "") |
187 expect := fmt.Sprintf(template, t.usage, t.doc) | 187 expect := fmt.Sprintf(template, t.usage, t.doc) |
188 c.Assert(bufferString(ctx.Stderr), Equals, expect) | 188 c.Assert(bufferString(ctx.Stderr), Equals, expect) |
189 } | 189 } |
190 } | 190 } |
OLD | NEW |