-
Notifications
You must be signed in to change notification settings - Fork 23
/
suite.go
74 lines (63 loc) · 1.42 KB
/
suite.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package suite
import (
"testing"
"github.com/gobuffalo/buffalo"
"github.com/gobuffalo/mw-csrf"
"github.com/gobuffalo/packr"
"github.com/markbates/willie"
"github.com/pkg/errors"
"github.com/stretchr/testify/suite"
)
type Action struct {
*Model
Session *buffalo.Session
Willie *willie.Willie
App *buffalo.App
csrf buffalo.MiddlewareFunc
}
func NewAction(app *buffalo.App) *Action {
as := &Action{
App: app,
Model: NewModel(),
}
return as
}
func NewActionWithFixtures(app *buffalo.App, box packr.Box) (*Action, error) {
m, err := NewModelWithFixtures(box)
if err != nil {
return nil, errors.WithStack(err)
}
as := &Action{
App: app,
Model: m,
}
return as, nil
}
func Run(t *testing.T, s suite.TestingSuite) {
suite.Run(t, s)
}
func (as *Action) HTML(u string, args ...interface{}) *willie.Request {
return as.Willie.HTML(u, args...)
}
func (as *Action) JSON(u string, args ...interface{}) *willie.JSON {
return as.Willie.JSON(u, args...)
}
func (as *Action) SetupTest() {
as.App.SessionStore = NewSessionStore()
s, _ := as.App.SessionStore.New(nil, as.App.SessionName)
as.Session = &buffalo.Session{
Session: s,
}
as.Model.SetupTest()
as.csrf = csrf.New
csrf.New = func(next buffalo.Handler) buffalo.Handler {
return func(c buffalo.Context) error {
return next(c)
}
}
as.Willie = willie.New(as.App)
}
func (as *Action) TearDownTest() {
csrf.New = as.csrf
as.Model.TearDownTest()
}