Пример #1
0
func TestRouterAPI(t *testing.T) {
	e := New()
	r := e.router

	for _, route := range api {
		r.Add(route.Method, route.Path, func(c *Context) error {
			return nil
		}, e)
	}

	response := NewResponse(httptest.NewRecorder())

	c := NewContext(nil, response, e)
	for _, route := range api {
		h, _ := r.Find(route.Method, route.Path, c)
		if assert.NotNil(t, h) {
			for i, n := range c.pnames {
				if assert.NotEmpty(t, n) {
					assert.Equal(t, ":"+n, c.P(i))
				}
			}
			h(c)
		}
	}
}
Пример #2
0
func TestVodkaFavicon(t *testing.T) {
	e := New()
	e.Favicon("examples/website/public/favicon.ico")
	c, b := request(GET, "/favicon.ico", e)
	assert.Equal(t, http.StatusOK, c)
	assert.NotEmpty(t, b)
}
Пример #3
0
func TestVodkaStatic(t *testing.T) {
	e := New()

	// OK
	e.Static("/scripts", "examples/website/public/scripts")
	c, b := request(GET, "/scripts/main.js", e)
	assert.Equal(t, http.StatusOK, c)
	assert.NotEmpty(t, b)

	// No file
	e.Static("/scripts", "examples/website/public/scripts")
	c, _ = request(GET, "/scripts/index.js", e)
	assert.Equal(t, http.StatusNotFound, c)

	// Directory
	e.Static("/scripts", "examples/website/public/scripts")
	c, _ = request(GET, "/scripts", e)
	assert.Equal(t, http.StatusForbidden, c)

	// Directory with index.html
	e.Static("/", "examples/website/public")
	c, r := request(GET, "/", e)
	assert.Equal(t, http.StatusOK, c)
	assert.Equal(t, true, strings.HasPrefix(r, "<!doctype html>"))

	// Sub-directory with index.html
	c, r = request(GET, "/folder", e)
	assert.Equal(t, http.StatusOK, c)
	assert.Equal(t, "sub directory", r)
}
Пример #4
0
func TestVodkaIndex(t *testing.T) {
	e := New()
	e.Index("examples/website/public/index.html")
	c, b := request(GET, "/", e)
	assert.Equal(t, http.StatusOK, c)
	assert.NotEmpty(t, b)
}