forked from gobuffalo/suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuite_test.go
41 lines (34 loc) · 885 Bytes
/
suite_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
40
41
package suite
import (
"fmt"
"testing"
"github.com/gobuffalo/buffalo"
"github.com/gobuffalo/buffalo/render"
)
type aSuite struct {
*Action
}
func Test_aSuite(t *testing.T) {
app := buffalo.New(buffalo.Options{})
app.GET("/session-hello", func(c buffalo.Context) error {
if n, ok := c.Session().Get("name").(string); ok {
return c.Render(200, render.String(n))
}
return c.Error(500, fmt.Errorf("could not find name in session"))
})
as := &aSuite{NewAction(app)}
Run(t, as)
}
func (as *aSuite) Test_Session() {
as.Session.Set("name", "Homer Simpson")
res := as.HTML("/session-hello").Get()
as.Equal(200, res.Code)
as.Contains(res.Body.String(), "Homer Simpson")
as.Session.Clear()
res = as.HTML("/session-hello").Get()
as.Equal(500, res.Code)
}
func (as *aSuite) Test_Session_Resets() {
res := as.HTML("/session-hello").Get()
as.Equal(500, res.Code)
}