forked from jcelliott/turnpike
-
Notifications
You must be signed in to change notification settings - Fork 3
/
dealer_test.go
87 lines (73 loc) · 2.56 KB
/
dealer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package turnpike
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestRegister(t *testing.T) {
Convey("Registering a procedure", t, func() {
dealer := NewDefaultDealer().(*defaultDealer)
callee := &TestSender{}
testProcedure := URI("turnpike.test.endpoint")
msg := &Register{Request: 123, Procedure: testProcedure}
dealer.Register(callee, msg)
Convey("The callee should have received a REGISTERED message", func() {
reg := callee.received.(*Registered).Registration
So(reg, ShouldNotEqual, 0)
})
Convey("The dealer should have the endpoint registered", func() {
reg := callee.received.(*Registered).Registration
reg2, ok := dealer.registrations[testProcedure]
So(ok, ShouldBeTrue)
So(reg, ShouldEqual, reg2)
proc, ok := dealer.procedures[reg]
So(ok, ShouldBeTrue)
So(proc.Procedure, ShouldEqual, testProcedure)
})
Convey("The same procedure cannot be registered more than once", func() {
msg := &Register{Request: 321, Procedure: testProcedure}
dealer.Register(callee, msg)
So(callee.received, ShouldHaveSameTypeAs, &Error{})
})
})
}
func TestUnregister(t *testing.T) {
dealer := NewDefaultDealer().(*defaultDealer)
callee := &TestSender{}
testProcedure := URI("turnpike.test.endpoint")
msg := &Register{Request: 123, Procedure: testProcedure}
dealer.Register(callee, msg)
reg := callee.received.(*Registered).Registration
Convey("Unregistering a procedure", t, func() {
msg := &Unregister{Request: 124, Registration: reg}
dealer.Unregister(callee, msg)
Convey("The callee should have received an UNREGISTERED message", func() {
unreg := callee.received.(*Unregistered).Request
So(unreg, ShouldNotEqual, 0)
})
Convey("The dealer should no longer have the endpoint registered", func() {
_, ok := dealer.registrations[testProcedure]
So(ok, ShouldBeFalse)
_, ok = dealer.procedures[reg]
So(ok, ShouldBeFalse)
})
})
}
func TestCall(t *testing.T) {
Convey("With a procedure registered", t, func() {
dealer := NewDefaultDealer().(*defaultDealer)
callee := &TestSender{}
testProcedure := URI("turnpike.test.endpoint")
msg := &Register{Request: 123, Procedure: testProcedure}
dealer.Register(callee, msg)
caller := &TestSender{}
Convey("Calling an invalid procedure", func() {
msg := &Call{Request: 124, Procedure: URI("turnpike.test.bad")}
dealer.Call(caller, msg)
Convey("The caller should have received an ERROR message", func() {
err := caller.received.(*Error).Error
So(err, ShouldEqual, WAMP_ERROR_NO_SUCH_PROCEDURE)
})
})
// TODO: call and yield
})
}