-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup_test.go
39 lines (33 loc) · 1.26 KB
/
setup_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package locale
import (
"testing"
"github.com/caddyserver/caddy"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/simia-tech/caddy-locale/method"
)
func TestLocaleParsing(t *testing.T) {
testFn := func(input string, expectLocales []string, expectMethods []method.Method, expectPathScope, expectCookieName string) func(*testing.T) {
return func(t *testing.T) {
localeHandler, err := parseLocale(caddy.NewTestController("http", input))
require.NoError(t, err)
assert.Equal(t, expectLocales, localeHandler.AvailableLocales)
assert.Equal(t, len(expectMethods), len(localeHandler.Methods))
assert.Equal(t, expectPathScope, localeHandler.PathScope)
assert.Equal(t, expectCookieName, localeHandler.Configuration.CookieName)
}
}
t.Run("OneLiner", testFn(`locale en de`,
[]string{"en", "de"}, []method.Method{method.Names["header"]}, "/", "locale"))
t.Run("PathScope", testFn(`locale en {
available de
path /
}`,
[]string{"en", "de"}, []method.Method{method.Names["header"]}, "/", "locale"))
t.Run("DetectMethods", testFn(`locale en de {
detect cookie header
cookie language
path /test
}`,
[]string{"en", "de"}, []method.Method{method.Names["cookie"], method.Names["header"]}, "/test", "language"))
}