Skip to content

Commit b656413

Browse files
committed
Fixed #37
Signed-off-by: Vishal Rana <vr@labstack.com>
1 parent 6d4864a commit b656413

File tree

2 files changed

+19
-36
lines changed

2 files changed

+19
-36
lines changed

echo.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ func (e *Echo) WebSocket(path string, h HandlerFunc) {
293293
}
294294

295295
func (e *Echo) add(method, path string, h Handler) {
296-
e.router.Add(method, e.prefix+path, wrapHandler(h), e)
296+
path = e.prefix + path
297+
e.router.Add(method, path, wrapHandler(h), e)
297298
key := runtime.FuncForPC(reflect.ValueOf(h).Pointer()).Name()
298299
e.uris[key] = path
299300
}

echo_test.go

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -307,58 +307,40 @@ func TestEchoWebSocket(t *testing.T) {
307307
origin := "http://localhost"
308308
url := fmt.Sprintf("ws://%s/ws", addr)
309309
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())
320316
}
321317
}
322318

323319
func TestEchoURL(t *testing.T) {
324320
e := New()
321+
325322
static := func(*Context) error { return nil }
326323
getUser := func(*Context) error { return nil }
327324
getFile := func(*Context) error { return nil }
325+
328326
e.Get("/static/file", static)
329327
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"))
350336
}
351337

352338
func TestEchoNotFound(t *testing.T) {
353339
e := New()
354-
355-
// Default NotFound handler
356340
r, _ := http.NewRequest(GET, "/files", nil)
357341
w := httptest.NewRecorder()
358342
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)
362344
}
363345

364346
func TestEchoHTTPError(t *testing.T) {

0 commit comments

Comments
 (0)