@@ -12,6 +12,7 @@ import (
12
12
"time"
13
13
14
14
"github.com/hybridgroup/gobot"
15
+ "github.com/hybridgroup/gobot/gobottest"
15
16
)
16
17
17
18
func initTestAPI () * API {
@@ -39,22 +40,22 @@ func TestRobeaux(t *testing.T) {
39
40
request , _ := http .NewRequest ("GET" , "/index.html" , nil )
40
41
response := httptest .NewRecorder ()
41
42
a .ServeHTTP (response , request )
42
- gobot .Assert (t , response .Code , 200 )
43
+ gobottest .Assert (t , response .Code , 200 )
43
44
// js assets
44
45
request , _ = http .NewRequest ("GET" , "/js/script.js" , nil )
45
46
response = httptest .NewRecorder ()
46
47
a .ServeHTTP (response , request )
47
- gobot .Assert (t , response .Code , 200 )
48
+ gobottest .Assert (t , response .Code , 200 )
48
49
// css assets
49
50
request , _ = http .NewRequest ("GET" , "/css/application.css" , nil )
50
51
response = httptest .NewRecorder ()
51
52
a .ServeHTTP (response , request )
52
- gobot .Assert (t , response .Code , 200 )
53
+ gobottest .Assert (t , response .Code , 200 )
53
54
// unknown asset
54
55
request , _ = http .NewRequest ("GET" , "/js/fake/file.js" , nil )
55
56
response = httptest .NewRecorder ()
56
57
a .ServeHTTP (response , request )
57
- gobot .Assert (t , response .Code , 404 )
58
+ gobottest .Assert (t , response .Code , 404 )
58
59
}
59
60
60
61
func TestIndex (t * testing.T ) {
@@ -64,8 +65,8 @@ func TestIndex(t *testing.T) {
64
65
65
66
a .ServeHTTP (response , request )
66
67
67
- gobot .Assert (t , http .StatusMovedPermanently , response .Code )
68
- gobot .Assert (t , "/index.html" , response .HeaderMap ["Location" ][0 ])
68
+ gobottest .Assert (t , http .StatusMovedPermanently , response .Code )
69
+ gobottest .Assert (t , "/index.html" , response .HeaderMap ["Location" ][0 ])
69
70
}
70
71
71
72
func TestMcp (t * testing.T ) {
@@ -76,8 +77,8 @@ func TestMcp(t *testing.T) {
76
77
77
78
var body map [string ]interface {}
78
79
json .NewDecoder (response .Body ).Decode (& body )
79
- gobot .Refute (t , body ["MCP" ].(map [string ]interface {})["robots" ], nil )
80
- gobot .Refute (t , body ["MCP" ].(map [string ]interface {})["commands" ], nil )
80
+ gobottest .Refute (t , body ["MCP" ].(map [string ]interface {})["robots" ], nil )
81
+ gobottest .Refute (t , body ["MCP" ].(map [string ]interface {})["commands" ], nil )
81
82
}
82
83
83
84
func TestMcpCommands (t * testing.T ) {
@@ -88,7 +89,7 @@ func TestMcpCommands(t *testing.T) {
88
89
89
90
var body map [string ]interface {}
90
91
json .NewDecoder (response .Body ).Decode (& body )
91
- gobot .Assert (t , body ["commands" ], []interface {}{"TestFunction" })
92
+ gobottest .Assert (t , body ["commands" ], []interface {}{"TestFunction" })
92
93
}
93
94
94
95
func TestExecuteMcpCommand (t * testing.T ) {
@@ -105,7 +106,7 @@ func TestExecuteMcpCommand(t *testing.T) {
105
106
a .ServeHTTP (response , request )
106
107
107
108
json .NewDecoder (response .Body ).Decode (& body )
108
- gobot .Assert (t , body .(map [string ]interface {})["result" ], "hey Beep Boop" )
109
+ gobottest .Assert (t , body .(map [string ]interface {})["result" ], "hey Beep Boop" )
109
110
110
111
// unknown command
111
112
request , _ = http .NewRequest ("GET" ,
@@ -117,7 +118,7 @@ func TestExecuteMcpCommand(t *testing.T) {
117
118
a .ServeHTTP (response , request )
118
119
119
120
json .NewDecoder (response .Body ).Decode (& body )
120
- gobot .Assert (t , body .(map [string ]interface {})["error" ], "Unknown Command" )
121
+ gobottest .Assert (t , body .(map [string ]interface {})["error" ], "Unknown Command" )
121
122
}
122
123
123
124
func TestRobots (t * testing.T ) {
@@ -128,7 +129,7 @@ func TestRobots(t *testing.T) {
128
129
129
130
var body map [string ]interface {}
130
131
json .NewDecoder (response .Body ).Decode (& body )
131
- gobot .Assert (t , len (body ["robots" ].([]interface {})), 3 )
132
+ gobottest .Assert (t , len (body ["robots" ].([]interface {})), 3 )
132
133
}
133
134
134
135
func TestRobot (t * testing.T ) {
@@ -141,14 +142,14 @@ func TestRobot(t *testing.T) {
141
142
142
143
var body map [string ]interface {}
143
144
json .NewDecoder (response .Body ).Decode (& body )
144
- gobot .Assert (t , body ["robot" ].(map [string ]interface {})["name" ].(string ), "Robot1" )
145
+ gobottest .Assert (t , body ["robot" ].(map [string ]interface {})["name" ].(string ), "Robot1" )
145
146
146
147
// unknown robot
147
148
request , _ = http .NewRequest ("GET" , "/api/robots/UnknownRobot1" , nil )
148
149
a .ServeHTTP (response , request )
149
150
150
151
json .NewDecoder (response .Body ).Decode (& body )
151
- gobot .Assert (t , body ["error" ], "No Robot found with the name UnknownRobot1" )
152
+ gobottest .Assert (t , body ["error" ], "No Robot found with the name UnknownRobot1" )
152
153
}
153
154
154
155
func TestRobotDevices (t * testing.T ) {
@@ -161,14 +162,14 @@ func TestRobotDevices(t *testing.T) {
161
162
162
163
var body map [string ]interface {}
163
164
json .NewDecoder (response .Body ).Decode (& body )
164
- gobot .Assert (t , len (body ["devices" ].([]interface {})), 3 )
165
+ gobottest .Assert (t , len (body ["devices" ].([]interface {})), 3 )
165
166
166
167
// unknown robot
167
168
request , _ = http .NewRequest ("GET" , "/api/robots/UnknownRobot1/devices" , nil )
168
169
a .ServeHTTP (response , request )
169
170
170
171
json .NewDecoder (response .Body ).Decode (& body )
171
- gobot .Assert (t , body ["error" ], "No Robot found with the name UnknownRobot1" )
172
+ gobottest .Assert (t , body ["error" ], "No Robot found with the name UnknownRobot1" )
172
173
}
173
174
174
175
func TestRobotCommands (t * testing.T ) {
@@ -181,14 +182,14 @@ func TestRobotCommands(t *testing.T) {
181
182
182
183
var body map [string ]interface {}
183
184
json .NewDecoder (response .Body ).Decode (& body )
184
- gobot .Assert (t , body ["commands" ], []interface {}{"robotTestFunction" })
185
+ gobottest .Assert (t , body ["commands" ], []interface {}{"robotTestFunction" })
185
186
186
187
// unknown robot
187
188
request , _ = http .NewRequest ("GET" , "/api/robots/UnknownRobot1/commands" , nil )
188
189
a .ServeHTTP (response , request )
189
190
190
191
json .NewDecoder (response .Body ).Decode (& body )
191
- gobot .Assert (t , body ["error" ], "No Robot found with the name UnknownRobot1" )
192
+ gobottest .Assert (t , body ["error" ], "No Robot found with the name UnknownRobot1" )
192
193
}
193
194
194
195
func TestExecuteRobotCommand (t * testing.T ) {
@@ -204,7 +205,7 @@ func TestExecuteRobotCommand(t *testing.T) {
204
205
a .ServeHTTP (response , request )
205
206
206
207
json .NewDecoder (response .Body ).Decode (& body )
207
- gobot .Assert (t , body .(map [string ]interface {})["result" ], "hey Robot1, Beep Boop" )
208
+ gobottest .Assert (t , body .(map [string ]interface {})["result" ], "hey Robot1, Beep Boop" )
208
209
209
210
// unknown command
210
211
request , _ = http .NewRequest ("GET" ,
@@ -216,7 +217,7 @@ func TestExecuteRobotCommand(t *testing.T) {
216
217
a .ServeHTTP (response , request )
217
218
218
219
json .NewDecoder (response .Body ).Decode (& body )
219
- gobot .Assert (t , body .(map [string ]interface {})["error" ], "Unknown Command" )
220
+ gobottest .Assert (t , body .(map [string ]interface {})["error" ], "Unknown Command" )
220
221
221
222
// uknown robot
222
223
request , _ = http .NewRequest ("GET" ,
@@ -227,7 +228,7 @@ func TestExecuteRobotCommand(t *testing.T) {
227
228
a .ServeHTTP (response , request )
228
229
229
230
json .NewDecoder (response .Body ).Decode (& body )
230
- gobot .Assert (t , body .(map [string ]interface {})["error" ], "No Robot found with the name UnknownRobot1" )
231
+ gobottest .Assert (t , body .(map [string ]interface {})["error" ], "No Robot found with the name UnknownRobot1" )
231
232
}
232
233
233
234
func TestRobotDevice (t * testing.T ) {
@@ -243,15 +244,15 @@ func TestRobotDevice(t *testing.T) {
243
244
244
245
var body map [string ]interface {}
245
246
json .NewDecoder (response .Body ).Decode (& body )
246
- gobot .Assert (t , body ["device" ].(map [string ]interface {})["name" ].(string ), "Device1" )
247
+ gobottest .Assert (t , body ["device" ].(map [string ]interface {})["name" ].(string ), "Device1" )
247
248
248
249
// unknown device
249
250
request , _ = http .NewRequest ("GET" ,
250
251
"/api/robots/Robot1/devices/UnknownDevice1" , nil )
251
252
a .ServeHTTP (response , request )
252
253
253
254
json .NewDecoder (response .Body ).Decode (& body )
254
- gobot .Assert (t , body ["error" ], "No Device found with the name UnknownDevice1" )
255
+ gobottest .Assert (t , body ["error" ], "No Device found with the name UnknownDevice1" )
255
256
}
256
257
257
258
func TestRobotDeviceCommands (t * testing.T ) {
@@ -267,7 +268,7 @@ func TestRobotDeviceCommands(t *testing.T) {
267
268
268
269
var body map [string ]interface {}
269
270
json .NewDecoder (response .Body ).Decode (& body )
270
- gobot .Assert (t , len (body ["commands" ].([]interface {})), 2 )
271
+ gobottest .Assert (t , len (body ["commands" ].([]interface {})), 2 )
271
272
272
273
// unknown device
273
274
request , _ = http .NewRequest ("GET" ,
@@ -276,7 +277,7 @@ func TestRobotDeviceCommands(t *testing.T) {
276
277
)
277
278
a .ServeHTTP (response , request )
278
279
json .NewDecoder (response .Body ).Decode (& body )
279
- gobot .Assert (t , body ["error" ], "No Device found with the name UnknownDevice1" )
280
+ gobottest .Assert (t , body ["error" ], "No Device found with the name UnknownDevice1" )
280
281
}
281
282
282
283
func TestExecuteRobotDeviceCommand (t * testing.T ) {
@@ -293,7 +294,7 @@ func TestExecuteRobotDeviceCommand(t *testing.T) {
293
294
a .ServeHTTP (response , request )
294
295
295
296
json .NewDecoder (response .Body ).Decode (& body )
296
- gobot .Assert (t , body .(map [string ]interface {})["result" ].(string ), "hello human" )
297
+ gobottest .Assert (t , body .(map [string ]interface {})["result" ].(string ), "hello human" )
297
298
298
299
// unknown command
299
300
request , _ = http .NewRequest ("GET" ,
@@ -305,7 +306,7 @@ func TestExecuteRobotDeviceCommand(t *testing.T) {
305
306
a .ServeHTTP (response , request )
306
307
307
308
json .NewDecoder (response .Body ).Decode (& body )
308
- gobot .Assert (t , body .(map [string ]interface {})["error" ], "Unknown Command" )
309
+ gobottest .Assert (t , body .(map [string ]interface {})["error" ], "Unknown Command" )
309
310
310
311
// unknown device
311
312
request , _ = http .NewRequest ("GET" ,
@@ -316,7 +317,7 @@ func TestExecuteRobotDeviceCommand(t *testing.T) {
316
317
a .ServeHTTP (response , request )
317
318
318
319
json .NewDecoder (response .Body ).Decode (& body )
319
- gobot .Assert (t , body .(map [string ]interface {})["error" ], "No Device found with the name UnknownDevice1" )
320
+ gobottest .Assert (t , body .(map [string ]interface {})["error" ], "No Device found with the name UnknownDevice1" )
320
321
321
322
}
322
323
@@ -330,14 +331,14 @@ func TestRobotConnections(t *testing.T) {
330
331
331
332
var body map [string ]interface {}
332
333
json .NewDecoder (response .Body ).Decode (& body )
333
- gobot .Assert (t , len (body ["connections" ].([]interface {})), 3 )
334
+ gobottest .Assert (t , len (body ["connections" ].([]interface {})), 3 )
334
335
335
336
// unknown robot
336
337
request , _ = http .NewRequest ("GET" , "/api/robots/UnknownRobot1/connections" , nil )
337
338
a .ServeHTTP (response , request )
338
339
339
340
json .NewDecoder (response .Body ).Decode (& body )
340
- gobot .Assert (t , body ["error" ], "No Robot found with the name UnknownRobot1" )
341
+ gobottest .Assert (t , body ["error" ], "No Robot found with the name UnknownRobot1" )
341
342
}
342
343
343
344
func TestRobotConnection (t * testing.T ) {
@@ -353,7 +354,7 @@ func TestRobotConnection(t *testing.T) {
353
354
354
355
var body map [string ]interface {}
355
356
json .NewDecoder (response .Body ).Decode (& body )
356
- gobot .Assert (t , body ["connection" ].(map [string ]interface {})["name" ].(string ), "Connection1" )
357
+ gobottest .Assert (t , body ["connection" ].(map [string ]interface {})["name" ].(string ), "Connection1" )
357
358
358
359
// unknown connection
359
360
request , _ = http .NewRequest ("GET" ,
@@ -362,7 +363,7 @@ func TestRobotConnection(t *testing.T) {
362
363
)
363
364
a .ServeHTTP (response , request )
364
365
json .NewDecoder (response .Body ).Decode (& body )
365
- gobot .Assert (t , body ["error" ], "No Connection found with the name UnknownConnection1" )
366
+ gobottest .Assert (t , body ["error" ], "No Connection found with the name UnknownConnection1" )
366
367
}
367
368
368
369
func TestRobotDeviceEvent (t * testing.T ) {
@@ -396,7 +397,7 @@ func TestRobotDeviceEvent(t *testing.T) {
396
397
case resp := <- respc :
397
398
reader := bufio .NewReader (resp .Body )
398
399
data , _ := reader .ReadString ('\n' )
399
- gobot .Assert (t , data , "data: \" event-data\" \n " )
400
+ gobottest .Assert (t , data , "data: \" event-data\" \n " )
400
401
done = true
401
402
case <- timer .C :
402
403
t .Error ("Not receiving data" )
@@ -411,7 +412,7 @@ func TestRobotDeviceEvent(t *testing.T) {
411
412
412
413
var body map [string ]interface {}
413
414
json .NewDecoder (response .Body ).Decode (& body )
414
- gobot .Assert (t , body ["error" ], "No Event found with the name UnknownEvent" )
415
+ gobottest .Assert (t , body ["error" ], "No Event found with the name UnknownEvent" )
415
416
}
416
417
417
418
func TestAPIRouter (t * testing.T ) {
@@ -421,35 +422,35 @@ func TestAPIRouter(t *testing.T) {
421
422
request , _ := http .NewRequest ("HEAD" , "/test" , nil )
422
423
response := httptest .NewRecorder ()
423
424
a .ServeHTTP (response , request )
424
- gobot .Assert (t , response .Code , 200 )
425
+ gobottest .Assert (t , response .Code , 200 )
425
426
426
427
a .Get ("/test" , func (res http.ResponseWriter , req * http.Request ) {})
427
428
request , _ = http .NewRequest ("GET" , "/test" , nil )
428
429
response = httptest .NewRecorder ()
429
430
a .ServeHTTP (response , request )
430
- gobot .Assert (t , response .Code , 200 )
431
+ gobottest .Assert (t , response .Code , 200 )
431
432
432
433
a .Post ("/test" , func (res http.ResponseWriter , req * http.Request ) {})
433
434
request , _ = http .NewRequest ("POST" , "/test" , nil )
434
435
response = httptest .NewRecorder ()
435
436
a .ServeHTTP (response , request )
436
- gobot .Assert (t , response .Code , 200 )
437
+ gobottest .Assert (t , response .Code , 200 )
437
438
438
439
a .Put ("/test" , func (res http.ResponseWriter , req * http.Request ) {})
439
440
request , _ = http .NewRequest ("PUT" , "/test" , nil )
440
441
response = httptest .NewRecorder ()
441
442
a .ServeHTTP (response , request )
442
- gobot .Assert (t , response .Code , 200 )
443
+ gobottest .Assert (t , response .Code , 200 )
443
444
444
445
a .Delete ("/test" , func (res http.ResponseWriter , req * http.Request ) {})
445
446
request , _ = http .NewRequest ("DELETE" , "/test" , nil )
446
447
response = httptest .NewRecorder ()
447
448
a .ServeHTTP (response , request )
448
- gobot .Assert (t , response .Code , 200 )
449
+ gobottest .Assert (t , response .Code , 200 )
449
450
450
451
a .Options ("/test" , func (res http.ResponseWriter , req * http.Request ) {})
451
452
request , _ = http .NewRequest ("OPTIONS" , "/test" , nil )
452
453
response = httptest .NewRecorder ()
453
454
a .ServeHTTP (response , request )
454
- gobot .Assert (t , response .Code , 200 )
455
+ gobottest .Assert (t , response .Code , 200 )
455
456
}
0 commit comments