func TestRouterMultiRoute(t *testing.T) { e := New() r := e.router // Routes r.Add(GET, "/users", func(c *Context) error { c.Set("path", "/users") return nil }, e) r.Add(GET, "/users/:id", func(c *Context) error { return nil }, e) c := NewContext(nil, new(Response), e) // Route > /users h, _ := r.Find(GET, "/users", c) if assert.NotNil(t, h) { h(c) assert.Equal(t, "/users", c.Get("path")) } // Route > /users/:id h, _ = r.Find(GET, "/users/1", c) if assert.NotNil(t, h) { assert.Equal(t, "1", c.P(0)) } // Route > /user h, _ = r.Find(GET, "/user", c) if assert.IsType(t, new(HTTPError), h(c)) { he := h(c).(*HTTPError) assert.Equal(t, http.StatusNotFound, he.code) } // Invalid Method for Resource c.response.writer = httptest.NewRecorder() h, _ = r.Find("INVALID", "/users", c) if assert.IsType(t, new(HTTPError), h(c)) { he := h(c).(*HTTPError) assert.Equal(t, http.StatusBadRequest, he.code) } }
func TestVodkaServer(t *testing.T) { e := New() s := e.Server(":1323") assert.IsType(t, &http.Server{}, s) }