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

Side by Side Diff: state/watcher_test.go

Issue 6332048: state: adding of FlagWatcher and integration into Service (Closed)
Patch Set: state: Adding of ExposedWatcher and integration into Service. Created 5 years, 6 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 | « state/watcher.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 state_test 1 package state_test
2 2
3 import ( 3 import (
4 . "launchpad.net/gocheck" 4 . "launchpad.net/gocheck"
5 "launchpad.net/gozk/zookeeper" 5 "launchpad.net/gozk/zookeeper"
6 "launchpad.net/juju-core/state" 6 "launchpad.net/juju-core/state"
7 "time" 7 "time"
8 ) 8 )
9 9
10 var serviceWatchConfigData = []map[string]interface{}{ 10 var serviceWatchConfigData = []map[string]interface{}{
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 select { 61 select {
62 case got, _ := <-configWatcher.Changes(): 62 case got, _ := <-configWatcher.Changes():
63 c.Fatalf("got unexpected change: %#v", got) 63 c.Fatalf("got unexpected change: %#v", got)
64 case <-time.After(100 * time.Millisecond): 64 case <-time.After(100 * time.Millisecond):
65 } 65 }
66 66
67 err = configWatcher.Stop() 67 err = configWatcher.Stop()
68 c.Assert(err, IsNil) 68 c.Assert(err, IsNil)
69 } 69 }
70 70
71 var serviceExposedTests = []struct {
72 test func(s *state.Service) error
73 want bool
74 }{
75 {func(s *state.Service) error { return nil }, false},
76 {func(s *state.Service) error { return s.SetExposed() }, true},
77 {func(s *state.Service) error { return s.ClearExposed() }, false},
78 {func(s *state.Service) error { return s.SetExposed() }, true},
79 }
80
81 func (s *StateSuite) TestServiceExposedConfig(c *C) {
82 dummy := s.addDummyCharm(c)
83 wordpress, err := s.st.AddService("wordpress", dummy)
84 c.Assert(err, IsNil)
85 c.Assert(wordpress.Name(), Equals, "wordpress")
86
87 exposed, err := wordpress.IsExposed()
88 c.Assert(err, IsNil)
89 c.Assert(exposed, Equals, false)
90 exposedWatcher := wordpress.WatchExposed()
91
92 for i, test := range serviceExposedTests {
93 c.Logf("test %d", i)
94 err := test.test(wordpress)
95 c.Assert(err, IsNil)
96 select {
97 case got, ok := <-exposedWatcher.Changes():
98 c.Assert(ok, Equals, true)
99 c.Assert(got, Equals, test.want)
100 case <-time.After(200 * time.Millisecond):
101 c.Fatalf("didn't get change: %#v", test.want)
102 }
103 }
104
105 select {
106 case got, _ := <-exposedWatcher.Changes():
107 c.Fatalf("got unexpected change: %#v", got)
108 case <-time.After(100 * time.Millisecond):
109 }
110
111 err = exposedWatcher.Stop()
112 c.Assert(err, IsNil)
113 }
114
71 func (s *StateSuite) TestServiceWatchConfigIllegalData(c *C) { 115 func (s *StateSuite) TestServiceWatchConfigIllegalData(c *C) {
72 dummy := s.addDummyCharm(c) 116 dummy := s.addDummyCharm(c)
73 wordpress, err := s.st.AddService("wordpress", dummy) 117 wordpress, err := s.st.AddService("wordpress", dummy)
74 c.Assert(err, IsNil) 118 c.Assert(err, IsNil)
75 c.Assert(wordpress.Name(), Equals, "wordpress") 119 c.Assert(wordpress.Name(), Equals, "wordpress")
76 configWatcher := wordpress.WatchConfig() 120 configWatcher := wordpress.WatchConfig()
77 121
78 // Receive empty change after service adding. 122 // Receive empty change after service adding.
79 select { 123 select {
80 case got, ok := <-configWatcher.Changes(): 124 case got, ok := <-configWatcher.Changes():
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 {[]string{"B"}, []string{"A", "B", "C"}, nil}, 497 {[]string{"B"}, []string{"A", "B", "C"}, nil},
454 {[]string{"A", "D", "C"}, []string{}, []string{"A", "D", "C"}}, 498 {[]string{"A", "D", "C"}, []string{}, []string{"A", "D", "C"}},
455 {[]string{}, []string{"A", "D", "C"}, nil}, 499 {[]string{}, []string{"A", "D", "C"}, nil},
456 } 500 }
457 501
458 func (*StateSuite) TestDiff(c *C) { 502 func (*StateSuite) TestDiff(c *C) {
459 for _, test := range diffTests { 503 for _, test := range diffTests {
460 c.Assert(test.want, DeepEquals, state.Diff(test.A, test.B)) 504 c.Assert(test.want, DeepEquals, state.Diff(test.A, test.B))
461 } 505 }
462 } 506 }
OLDNEW
« no previous file with comments | « state/watcher.go ('k') | no next file » | no next file with comments »

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