示例#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"))
}
示例#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"))
}
示例#3
0
func TestRoute_Match_WithOptionalSegments(t *testing.T) {
	routePath := "((/sites/:site_id)?/categories/:category_id)?/posts/:id"
	tests := [][]string{
		{
			"/sites/foo/categories/bar/posts/baz",
			"category_id=bar&id=baz&site_id=foo",
		},
		{
			"/categories/bar/posts/baz",
			"category_id=bar&id=baz",
		},
		{
			"/posts/baz",
			"id=baz",
		},
	}
	route := NewRoute(routePath, httpHandlerExample)
	for _, opts := range tests {
		requestPath := opts[0]
		expectedQuery := opts[1]
		values, ok := route.Match(requestPath)
		assert.True(t, ok)
		assert.Equal(t, expectedQuery, values.Encode())
	}
}
示例#4
0
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())
}
示例#5
0
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)
}
示例#6
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))
}
示例#7
0
func TestTranslate(t *testing.T) {
	defer resetLocales()

	en := NewLocale("en")
	en.Add("greeting", "hello")
	en.Add("greeting2", "hello2")
	AddLocale(en)

	it := NewLocale("it")
	it.Add("greeting", "ciao")
	AddLocale(it)

	var value string
	var err error

	err = SetLocale("en")
	assert.Nil(t, err)
	assert.Equal(t, en, currentLocale)

	value, err = Translate("greeting")
	assert.Nil(t, err)
	assert.Equal(t, "hello", value)

	value, err = Translate("greeting2")
	assert.Nil(t, err)
	assert.Equal(t, "hello2", value)

	err = SetLocale("it")
	assert.Nil(t, err)
	assert.Equal(t, it, currentLocale)

	value, err = Translate("greeting")
	assert.Nil(t, err)
	assert.Equal(t, "ciao", value)

	value, err = Translate("greeting2")
	assert.NotNil(t, err)
	assert.Type(t, "*i18n.TranslationMissing", err)

	err = SetLocale("es")
	assert.NotNil(t, err)
	assert.Type(t, "*i18n.LocaleMissing", err)
	assert.True(t, currentLocale == nil)

	value, err = Translate("greeting")
	assert.NotNil(t, err)
	assert.Equal(t, "Current locale is not set", err.Error())
}
示例#8
0
func TestBundler_InitOutputPath(t *testing.T) {
	defer testRemoveTestDataFolder()

	b := testNewBundler()

	_, err := os.Stat(testDataFolder)
	if err == nil {
		t.Errorf("%s followed should must be removed before runnning tests", testDataFolder)
	}

	b.initOutputPath()

	fi, err := os.Stat(b.outputPath)
	assert.Nil(t, err)
	assert.True(t, fi.IsDir())
}
示例#9
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"))
}
示例#10
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"))
}