Exemple #1
0
func TestIsValidGeometry(t *testing.T) {
	validGeometries = map[string]bool{}
	assert.False(t, IsValidGeometry("200x200"))

	validGeometries = map[string]bool{"*": true}
	assert.True(t, IsValidGeometry("200x200"))

	validGeometries = map[string]bool{"200x100": true, "200x": true, "x100": true}
	assert.False(t, IsValidGeometry("200x200"))
	assert.True(t, IsValidGeometry("200x100"))
	assert.True(t, IsValidGeometry("200x"))
	assert.True(t, IsValidGeometry("x100"))
}
Exemple #2
0
func TestIsWatchedFile(t *testing.T) {
	// valid extensions
	assert.True(t, isWatchedFile("test.go"))
	assert.True(t, isWatchedFile("test.tpl"))
	assert.True(t, isWatchedFile("test.tmpl"))
	assert.True(t, isWatchedFile("test.html"))

	/* // invalid extensions */
	assert.False(t, isWatchedFile("test.css"))
	assert.False(t, isWatchedFile("test-executable"))

	// files in tmp
	assert.False(t, isWatchedFile("./tmp/test.go"))
}
func TestResponseWriter_Write(t *testing.T) {
	routerEnv := make(map[string]interface{})
	rw, recorder := buildTestResponseWriter(&routerEnv)

	assert.False(t, rw.Written())

	rw.Write([]byte("foo"))

	assert.True(t, rw.Written())
	assert.Equal(t, []byte("foo"), recorder.Body.Bytes())
}
func TestResponseWriter_WriteHeader(t *testing.T) {
	routerEnv := make(map[string]interface{})
	rw, recorder := buildTestResponseWriter(&routerEnv)

	assert.False(t, rw.Written())

	rw.WriteHeader(http.StatusUnauthorized)

	assert.True(t, rw.Written())
	assert.Equal(t, http.StatusUnauthorized, rw.StatusCode())
	assert.Equal(t, http.StatusUnauthorized, recorder.Code)
}
Exemple #5
0
func TestRoute_Match(t *testing.T) {
	tests := [][]string{
		{
			"/",
			"/",
			"",
		},
		{
			"/:foo/?",
			"/bar",
			"foo=bar",
		},
		{
			"/:foo/?",
			"/bar/", // with trailing slash
			"foo=bar",
		},
		{
			"/categories/:category_id/posts/:id",
			"/categories/foo/posts/bar",
			"category_id=foo&id=bar",
		},
		{
			"/pages/:page_path*",
			"/pages/foo/bar/baz",
			"page_path=foo%2Fbar%2Fbaz",
		},
		{
			"/pages/:page.html",
			"/pages/foo.html",
			"page=foo",
		},
	}

	for _, opts := range tests {
		routePath := opts[0]
		requestPath := opts[1]
		expectedQuery := opts[2]

		route := NewRoute(routePath, httpHandlerExample)
		values, ok := route.Match(requestPath)
		assert.True(t, ok)
		assert.Equal(t, expectedQuery, values.Encode())
	}

	route := NewRoute("/foo", httpHandlerExample)
	values, ok := route.Match("/bar")
	assert.False(t, ok)
	assert.Equal(t, values, make(url.Values))
}
Exemple #6
0
func TestIsValidUUID(t *testing.T) {
	assert.True(t, IsValidUUID("77a591d0-ed7c-0130-97ce-28cfe91367b5"))
	assert.False(t, IsValidUUID("77a591d0-ed7c-0130-97ce-28cfe91367b5i-XXX"))
	assert.False(t, IsValidUUID("bad UUI"))
}
Exemple #7
0
func TestIsIgnoredFolder(t *testing.T) {
	assert.True(t, isIgnoredFolder("assets/node_module"))
	assert.False(t, isIgnoredFolder("app/controllers"))
	assert.True(t, isIgnoredFolder("tmp/pid"))
}