github.com/jasonish/buffalo@v0.8.2-0.20170413145823-bacbdd415f1b/middleware/i18n/i18n_test.go (about) 1 package i18n 2 3 import ( 4 "log" 5 "testing" 6 7 "github.com/gobuffalo/buffalo" 8 "github.com/gobuffalo/buffalo/render" 9 "github.com/gobuffalo/packr" 10 "github.com/markbates/willie" 11 "github.com/stretchr/testify/require" 12 ) 13 14 func app() *buffalo.App { 15 app := buffalo.Automatic(buffalo.Options{}) 16 17 r := render.New(render.Options{ 18 TemplatesBox: packr.NewBox("./templates"), 19 }) 20 21 // Setup and use translations: 22 t, err := New(packr.NewBox("./locales"), "en-US") 23 if err != nil { 24 log.Fatal(err) 25 } 26 app.Use(t.Middleware()) 27 app.GET("/", func(c buffalo.Context) error { 28 return c.Render(200, r.HTML("index.html")) 29 }) 30 return app 31 } 32 33 func Test_i18n(t *testing.T) { 34 r := require.New(t) 35 36 w := willie.New(app()) 37 res := w.Request("/").Get() 38 r.Equal("Hello, World!\n", res.Body.String()) 39 }