-
-
Notifications
You must be signed in to change notification settings - Fork 39
/
mock.go
146 lines (110 loc) · 2.87 KB
/
mock.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright 2021 Flamego. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package flamego
import (
"net/http"
"github.com/flamego/flamego/inject"
)
var _ Context = (*mockContext)(nil)
type mockContext struct {
inject.Injector
responseWriter_ func() ResponseWriter
request_ func() *Request
params Params
urlPath_ urlPather
written_ func() bool
next_ func()
remoteAddr_ func() string
redirect_ func(string, ...int)
params_ func() Params
param_ func(string) string
paramInt_ func(string) int
paramInt64_ func(string) int64
query_ func(string) string
queryTrim_ func(string) string
queryStrings_ func(string) []string
queryUnescape_ func(string) string
queryBool_ func(string) bool
queryInt_ func(string) int
queryInt64_ func(string) int64
queryFloat64_ func(string) float64
setCookie_ func(cookie http.Cookie)
cookie_ func(string) string
setAction_ func(Handler)
run_ func()
}
func newMockContext() *mockContext {
return &mockContext{
Injector: inject.New(),
}
}
func (c *mockContext) ResponseWriter() ResponseWriter {
return c.responseWriter_()
}
func (c *mockContext) Request() *Request {
return c.request_()
}
func (c *mockContext) URLPath(name string, pairs ...string) string {
return c.urlPath_(name, pairs...)
}
func (c *mockContext) Written() bool {
return c.written_()
}
func (c *mockContext) Next() {
c.next_()
}
func (c *mockContext) setAction(h Handler) {
c.setAction_(h)
}
func (c *mockContext) run() {
c.run_()
}
func (c *mockContext) RemoteAddr() string {
return c.remoteAddr_()
}
func (c *mockContext) Redirect(location string, status ...int) {
c.redirect_(location, status...)
}
func (c *mockContext) Params() Params {
return c.params_()
}
func (c *mockContext) Param(name string) string {
return c.param_(name)
}
func (c *mockContext) ParamInt(name string) int {
return c.paramInt_(name)
}
func (c *mockContext) ParamInt64(name string) int64 {
return c.paramInt64_(name)
}
func (c *mockContext) Query(name string) string {
return c.query_(name)
}
func (c *mockContext) QueryTrim(name string) string {
return c.queryTrim_(name)
}
func (c *mockContext) QueryStrings(name string) []string {
return c.queryStrings_(name)
}
func (c *mockContext) QueryUnescape(name string) string {
return c.queryUnescape_(name)
}
func (c *mockContext) QueryBool(name string) bool {
return c.queryBool_(name)
}
func (c *mockContext) QueryInt(name string) int {
return c.queryInt_(name)
}
func (c *mockContext) QueryInt64(name string) int64 {
return c.queryInt64_(name)
}
func (c *mockContext) QueryFloat64(name string) float64 {
return c.queryFloat64_(name)
}
func (c *mockContext) SetCookie(cookie http.Cookie) {
c.setCookie_(cookie)
}
func (c *mockContext) Cookie(name string) string {
return c.cookie_(name)
}