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

Side by Side Diff: worker/uniter/jujuc/util_test.go

Issue 8701043: Use the new set.Strings
Patch Set: Use the new set.Strings Created 11 years, 11 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:
View unified diff | Download patch
« no previous file with comments | « worker/uniter/jujuc/ports_test.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package jujuc_test 1 package jujuc_test
2 2
3 import ( 3 import (
4 "bytes" 4 "bytes"
5 "fmt" 5 "fmt"
6 "io" 6 "io"
7 . "launchpad.net/gocheck" 7 . "launchpad.net/gocheck"
8 "launchpad.net/juju-core/state" 8 "launchpad.net/juju-core/state"
9 "launchpad.net/juju-core/utils/set"
9 "launchpad.net/juju-core/worker/uniter/jujuc" 10 "launchpad.net/juju-core/worker/uniter/jujuc"
10 "sort" 11 "sort"
11 "testing" 12 "testing"
12 ) 13 )
13 14
14 func TestPackage(t *testing.T) { TestingT(t) } 15 func TestPackage(t *testing.T) { TestingT(t) }
15 16
16 func bufferString(w io.Writer) string { 17 func bufferString(w io.Writer) string {
17 return w.(*bytes.Buffer).String() 18 return w.(*bytes.Buffer).String()
18 } 19 }
(...skipping 20 matching lines...) Expand all
39 }, 40 },
40 } 41 }
41 } 42 }
42 43
43 func (s *ContextSuite) GetHookContext(c *C, relid int, remote string) *Context { 44 func (s *ContextSuite) GetHookContext(c *C, relid int, remote string) *Context {
44 if relid != -1 { 45 if relid != -1 {
45 _, found := s.rels[relid] 46 _, found := s.rels[relid]
46 c.Assert(found, Equals, true) 47 c.Assert(found, Equals, true)
47 } 48 }
48 return &Context{ 49 return &Context{
49 ports: map[string]bool{},
50 relid: relid, 50 relid: relid,
51 remote: remote, 51 remote: remote,
52 rels: s.rels, 52 rels: s.rels,
53 } 53 }
54 } 54 }
55 55
56 func setSettings(c *C, ru *state.RelationUnit, settings map[string]interface{}) { 56 func setSettings(c *C, ru *state.RelationUnit, settings map[string]interface{}) {
57 node, err := ru.Settings() 57 node, err := ru.Settings()
58 c.Assert(err, IsNil) 58 c.Assert(err, IsNil)
59 for _, k := range node.Keys() { 59 for _, k := range node.Keys() {
60 node.Delete(k) 60 node.Delete(k)
61 } 61 }
62 node.Update(settings) 62 node.Update(settings)
63 _, err = node.Write() 63 _, err = node.Write()
64 c.Assert(err, IsNil) 64 c.Assert(err, IsNil)
65 } 65 }
66 66
67 type Context struct { 67 type Context struct {
68 » ports map[string]bool 68 » ports set.Strings
69 relid int 69 relid int
70 remote string 70 remote string
71 rels map[int]*ContextRelation 71 rels map[int]*ContextRelation
72 } 72 }
73 73
74 func (c *Context) UnitName() string { 74 func (c *Context) UnitName() string {
75 return "u/0" 75 return "u/0"
76 } 76 }
77 77
78 func (c *Context) PublicAddress() (string, bool) { 78 func (c *Context) PublicAddress() (string, bool) {
79 return "gimli.minecraft.example.com", true 79 return "gimli.minecraft.example.com", true
80 } 80 }
81 81
82 func (c *Context) PrivateAddress() (string, bool) { 82 func (c *Context) PrivateAddress() (string, bool) {
83 return "192.168.0.99", true 83 return "192.168.0.99", true
84 } 84 }
85 85
86 func (c *Context) OpenPort(protocol string, port int) error { 86 func (c *Context) OpenPort(protocol string, port int) error {
87 » c.ports[fmt.Sprintf("%d/%s", port, protocol)] = true 87 » c.ports.Add(fmt.Sprintf("%d/%s", port, protocol))
88 return nil 88 return nil
89 } 89 }
90 90
91 func (c *Context) ClosePort(protocol string, port int) error { 91 func (c *Context) ClosePort(protocol string, port int) error {
92 » delete(c.ports, fmt.Sprintf("%d/%s", port, protocol)) 92 » c.ports.Remove(fmt.Sprintf("%d/%s", port, protocol))
93 return nil 93 return nil
94 } 94 }
95 95
96 func (c *Context) Config() (map[string]interface{}, error) { 96 func (c *Context) Config() (map[string]interface{}, error) {
97 return map[string]interface{}{ 97 return map[string]interface{}{
98 "monsters": false, 98 "monsters": false,
99 "spline-reticulation": 45.0, 99 "spline-reticulation": 45.0,
100 "title": "My Title", 100 "title": "My Title",
101 "username": "admin001", 101 "username": "admin001",
102 }, nil 102 }, nil
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 delete(s, k) 177 delete(s, k)
178 } 178 }
179 179
180 func (s Settings) Map() map[string]interface{} { 180 func (s Settings) Map() map[string]interface{} {
181 r := map[string]interface{}{} 181 r := map[string]interface{}{}
182 for k, v := range s { 182 for k, v := range s {
183 r[k] = v 183 r[k] = v
184 } 184 }
185 return r 185 return r
186 } 186 }
OLDNEW
« no previous file with comments | « worker/uniter/jujuc/ports_test.go ('k') | no next file » | no next file with comments »

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