github.com/segakazzz/buffalo@v0.16.22-0.20210119082501-1f52048d3feb/options_test.go (about) 1 package buffalo 2 3 import ( 4 "net/http" 5 "strings" 6 "testing" 7 8 "github.com/gobuffalo/envy" 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestOptions_NewOptions(t *testing.T) { 13 tests := []struct { 14 name string 15 env string 16 secret string 17 expectErr string 18 }{ 19 {name: "Development doesn't fail with no secret", env: "development", secret: "", expectErr: "securecookie:"}, 20 {name: "Development doesn't fail with secret set", env: "development", secret: "secrets", expectErr: "securecookie:"}, 21 {name: "Test doesn't fail with secret set", env: "test", secret: "", expectErr: "securecookie:"}, 22 {name: "Test doesn't fail with secret set", env: "test", secret: "secrets", expectErr: "securecookie:"}, 23 {name: "Production fails with no secret", env: "production", secret: "", expectErr: "securecookie:"}, 24 {name: "Production doesn't fail with secret set", env: "production", secret: "secrets", expectErr: "securecookie:"}, 25 } 26 27 for _, test := range tests { 28 t.Run(test.name, func(t *testing.T) { 29 r := require.New(t) 30 envy.Temp(func() { 31 envy.Set("GO_ENV", test.env) 32 envy.Set("SESSION_SECRET", test.secret) 33 34 opts := NewOptions() 35 36 req, _ := http.NewRequest("GET", "/", strings.NewReader("")) 37 req.AddCookie(&http.Cookie{Name: "_buffalo_session"}) 38 39 _, err := opts.SessionStore.New(req, "_buffalo_session") 40 41 r.Error(err) 42 r.Contains(err.Error(), test.expectErr) 43 }) 44 }) 45 } 46 }