-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware_test.go
56 lines (54 loc) · 1.26 KB
/
middleware_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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package orm
import (
"context"
"github.com/stretchr/testify/assert"
"testing"
)
func Test_Middleware(t *testing.T) {
testCases := []struct {
name string
wantErr error
mdls []Middleware
}{
{
name: "one middleware",
mdls: func() []Middleware {
var mdl Middleware = func(next HandleFunc) HandleFunc {
return func(ctx context.Context, queryContext *QueryContext) *QueryResult {
return &QueryResult{}
}
}
return []Middleware{mdl}
}(),
},
{
name: "many middleware",
mdls: func() []Middleware {
mdl1 := func(next HandleFunc) HandleFunc {
return func(ctx context.Context, queryContext *QueryContext) *QueryResult {
return &QueryResult{Result: "mdl1"}
}
}
mdl2 := func(next HandleFunc) HandleFunc {
return func(ctx context.Context, queryContext *QueryContext) *QueryResult {
return &QueryResult{Result: "mdl2"}
}
}
return []Middleware{mdl1, mdl2}
}(),
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
orm, err := Open("sqlite3", "file:test.db?cache=shared&mode=memory",
DBWithMiddlewares(tc.mdls...))
if err != nil {
t.Error(err)
}
defer func() {
_ = orm.Close()
}()
assert.EqualValues(t, tc.mdls, orm.ms)
})
}
}