forked from gobuffalo/suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuite.go
60 lines (50 loc) · 1.17 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
package suite
import (
"testing"
"github.com/gobuffalo/buffalo"
"github.com/gobuffalo/buffalo/middleware"
"github.com/markbates/willie"
"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 Run(t *testing.T, s suite.TestingSuite) {
suite.Run(t, s)
}
func (as *Action) HTML(u string, args ...interface{}) *willie.Request {
return as.Willie.Request(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 = middleware.CSRF
middleware.CSRF = 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() {
middleware.CSRF = as.csrf
as.Model.TearDownTest()
}