@@ -8,51 +8,11 @@ import (
8
8
"net/http"
9
9
"net/url"
10
10
"testing"
11
- "time"
12
11
13
12
"github.com/gorilla/websocket"
14
- "github.com/meteorhacks/goddp/server"
15
13
)
16
14
17
- var (
18
- URL = "http://localhost:1337/websocket"
19
- ORIGIN = "http://localhost:1337"
20
- ADDR = "localhost:1337"
21
- s server.Server
22
- )
23
-
24
- type MethodError struct {
25
- Error string `json:"error"`
26
- }
27
-
28
- type Message struct {
29
- Msg string `json:"msg"`
30
- Session string `json:"session"`
31
- ID string `json:"id"`
32
- Result float64 `json:"result"`
33
- Error MethodError `json:"error"`
34
- }
35
-
36
- func TestStartServer (t * testing.T ) {
37
- s = server .New ()
38
-
39
- s .Method ("double" , func (ctx server.MethodContext ) {
40
- n , ok := ctx .Params [0 ].(float64 )
41
-
42
- if ! ok {
43
- ctx .SendError ("invalid parameters" )
44
- } else {
45
- ctx .SendResult (n * 2 )
46
- }
47
-
48
- ctx .SendUpdated ()
49
- })
50
-
51
- go s .Listen (":1337" )
52
- time .Sleep (100 * time .Millisecond )
53
- }
54
-
55
- func TestConnect (t * testing.T ) {
15
+ func Test_WS_Connect (t * testing.T ) {
56
16
ws , err := newClient ()
57
17
if err != nil {
58
18
t .Error ("websocket connection failed" )
@@ -72,7 +32,7 @@ func TestConnect(t *testing.T) {
72
32
}
73
33
}
74
34
75
- func TestPingWithoutId (t * testing.T ) {
35
+ func Test_WS_PingWithoutId (t * testing.T ) {
76
36
ws , err := newClient ()
77
37
if err != nil {
78
38
t .Error ("websocket connection failed" )
@@ -91,7 +51,7 @@ func TestPingWithoutId(t *testing.T) {
91
51
}
92
52
}
93
53
94
- func TestPingWithId (t * testing.T ) {
54
+ func Test_WS_PingWithId (t * testing.T ) {
95
55
ws , err := newClient ()
96
56
if err != nil {
97
57
t .Error ("websocket connection failed" )
@@ -114,7 +74,7 @@ func TestPingWithId(t *testing.T) {
114
74
}
115
75
}
116
76
117
- func TestMethodResult (t * testing.T ) {
77
+ func Test_WS_MethodResult (t * testing.T ) {
118
78
ws , err := newClient ()
119
79
if err != nil {
120
80
t .Error ("websocket connection failed" )
@@ -141,7 +101,7 @@ func TestMethodResult(t *testing.T) {
141
101
}
142
102
}
143
103
144
- func TestMethodError (t * testing.T ) {
104
+ func Test_WS_MethodError (t * testing.T ) {
145
105
ws , err := newClient ()
146
106
if err != nil {
147
107
t .Error ("websocket connection failed" )
@@ -169,7 +129,7 @@ func TestMethodError(t *testing.T) {
169
129
}
170
130
171
131
func newClient () (* websocket.Conn , error ) {
172
- u , _ := url .Parse (URL )
132
+ u , _ := url .Parse (WSURL )
173
133
conn , err := net .Dial ("tcp" , ADDR )
174
134
175
135
if err != nil {
0 commit comments