~chipaca/ubuntu-push/conflag-maybe

« back to all changes in this revision

Viewing changes to bus/testing/testing_endpoint_test.go

  • Committer: Tarmac
  • Author(s): john.lenton at canonical
  • Date: 2014-01-22 10:51:37 UTC
  • mfrom: (9.3.15 multi-valued)
  • Revision ID: tarmac-20140122105137-wxraowrgim634i27
[r=pedronis] Made the bus support multi-valued signals (preparatory for notifications). Also added tests for TestingBus.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
        c.Check(v, Equals, m)
40
40
}
41
41
 
 
42
// Test the same Call() but with multi-valued endpoint
 
43
func (s *TestingEndpointSuite) TestMultiValuedCall(c *C) {
 
44
        var m, n uint32 = 42, 17
 
45
        endp := NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{m}, []interface{}{n})
 
46
        v, e := endp.Call("what")
 
47
        c.Check(e, IsNil)
 
48
        c.Check(v, Equals, m)
 
49
}
 
50
 
42
51
// Test that Call() with a negative condition returns an error.
43
52
func (s *TestingEndpointSuite) TestCallFails(c *C) {
44
53
        endp := NewTestingEndpoint(condition.Work(false))
50
59
// a helpful message.
51
60
func (s *TestingEndpointSuite) TestCallPanicsWithNiceMessage(c *C) {
52
61
        endp := NewTestingEndpoint(condition.Work(true))
53
 
        c.Check(func() { endp.Call("") }, PanicMatches, "No return values provided!")
 
62
        c.Check(func() { endp.Call("") }, PanicMatches, "No return values provided.*")
 
63
}
 
64
 
 
65
// Test that Call() with a positive condition and an empty return value panics
 
66
// with a helpful message.
 
67
func (s *TestingEndpointSuite) TestCallPanicsWithNiceMessage2(c *C) {
 
68
        endp := NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{})
 
69
        c.Check(func() { endp.Call("") }, PanicMatches, "Wrong number of values provided.*")
 
70
}
 
71
 
 
72
// Test Call() with positive condition and the wrong number of arguments also
 
73
// fails with a helpful message
 
74
func (s *TestingEndpointSuite) TestMultiValuedCallPanicsWhenWrongNumberOfValues(c *C) {
 
75
        var m, n uint32 = 42, 17
 
76
        endp := NewMultiValuedTestingEndpoint(condition.Work(true), []interface{}{m, n})
 
77
        c.Check(func() { endp.Call("") }, PanicMatches, "Wrong number of values provided.*")
54
78
}
55
79
 
56
80
// Test that WatchSignal() with a positive condition sends the provided return
59
83
        var m, n uint32 = 42, 17
60
84
        endp := NewTestingEndpoint(condition.Work(true), m, n)
61
85
        ch := make(chan uint32)
62
 
        e := endp.WatchSignal("what", func(u interface{}) { ch <- u.(uint32) }, func() { close(ch) })
 
86
        e := endp.WatchSignal("what", func(us ...interface{}) { ch <- us[0].(uint32) }, func() { close(ch) })
63
87
        c.Check(e, IsNil)
64
88
        c.Check(<-ch, Equals, m)
65
89
        c.Check(<-ch, Equals, n)
66
90
}
67
91
 
 
92
// Test that WatchSignal() calls the destructor callback when it runs out values
 
93
func (s *TestingEndpointSuite) TestWatchDestructor(c *C) {
 
94
        endp := NewTestingEndpoint(condition.Work(true))
 
95
        ch := make(chan uint32)
 
96
        e := endp.WatchSignal("what", func(us ...interface{}) {}, func() { close(ch) })
 
97
        c.Check(e, IsNil)
 
98
        _, ok := <-ch
 
99
        c.Check(ok, Equals, false)
 
100
}
 
101
 
 
102
// Test the endpoint can be closed
 
103
func (s *TestingEndpointSuite) TestCloser(c *C) {
 
104
        endp := NewTestingEndpoint(condition.Work(true))
 
105
        endp.Close()
 
106
        // ... yay?
 
107
}
 
108
 
68
109
// Test that WatchSignal() with a negative condition returns an error.
69
110
func (s *TestingEndpointSuite) TestWatchFails(c *C) {
70
111
        endp := NewTestingEndpoint(condition.Work(false))
71
 
        e := endp.WatchSignal("what", func(u interface{}) {}, func() {})
 
112
        e := endp.WatchSignal("what", func(us ...interface{}) {}, func() {})
72
113
        c.Check(e, NotNil)
73
114
}
74
115