@@ -307,58 +307,40 @@ func TestEchoWebSocket(t *testing.T) {
307
307
origin := "http://localhost"
308
308
url := fmt .Sprintf ("ws://%s/ws" , addr )
309
309
ws , err := websocket .Dial (url , "" , origin )
310
- if err != nil {
311
- t .Fatal (err )
312
- }
313
- ws .Write ([]byte ("test" ))
314
- defer ws .Close ()
315
- buf := new (bytes.Buffer )
316
- buf .ReadFrom (ws )
317
- s := buf .String ()
318
- if s != "test" {
319
- t .Errorf ("expected `test`, got %s." , s )
310
+ if assert .NoError (t , err ) {
311
+ ws .Write ([]byte ("test" ))
312
+ defer ws .Close ()
313
+ buf := new (bytes.Buffer )
314
+ buf .ReadFrom (ws )
315
+ assert .Equal (t , "test" , buf .String ())
320
316
}
321
317
}
322
318
323
319
func TestEchoURL (t * testing.T ) {
324
320
e := New ()
321
+
325
322
static := func (* Context ) error { return nil }
326
323
getUser := func (* Context ) error { return nil }
327
324
getFile := func (* Context ) error { return nil }
325
+
328
326
e .Get ("/static/file" , static )
329
327
e .Get ("/users/:id" , getUser )
330
- e .Get ("/users/:uid/files/:fid" , getFile )
331
-
332
- if e .URL (static ) != "/static/file" {
333
- t .Error ("uri should be /static/file" )
334
- }
335
- if e .URI (static ) != "/static/file" {
336
- t .Error ("uri should be /static/file" )
337
- }
338
- if e .URI (getUser ) != "/users/:id" {
339
- t .Error ("uri should be /users/:id" )
340
- }
341
- if e .URI (getUser , "1" ) != "/users/1" {
342
- t .Error ("uri should be /users/1" )
343
- }
344
- if e .URI (getFile , "1" ) != "/users/1/files/:fid" {
345
- t .Error ("uri should be /users/1/files/:fid" )
346
- }
347
- if e .URI (getFile , "1" , "1" ) != "/users/1/files/1" {
348
- t .Error ("uri should be /users/1/files/1" )
349
- }
328
+ g := e .Group ("/group" )
329
+ g .Get ("/users/:uid/files/:fid" , getFile )
330
+
331
+ assert .Equal (t , "/static/file" , e .URL (static ))
332
+ assert .Equal (t , "/users/:id" , e .URL (getUser ))
333
+ assert .Equal (t , "/users/1" , e .URL (getUser , "1" ))
334
+ assert .Equal (t , "/group/users/1/files/:fid" , e .URL (getFile , "1" ))
335
+ assert .Equal (t , "/group/users/1/files/1" , e .URL (getFile , "1" , "1" ))
350
336
}
351
337
352
338
func TestEchoNotFound (t * testing.T ) {
353
339
e := New ()
354
-
355
- // Default NotFound handler
356
340
r , _ := http .NewRequest (GET , "/files" , nil )
357
341
w := httptest .NewRecorder ()
358
342
e .ServeHTTP (w , r )
359
- if w .Code != http .StatusNotFound {
360
- t .Errorf ("status code should be 404, found %d" , w .Code )
361
- }
343
+ assert .Equal (t , http .StatusNotFound , w .Code )
362
344
}
363
345
364
346
func TestEchoHTTPError (t * testing.T ) {
0 commit comments