@@ -2,13 +2,9 @@ package web
2
2
3
3
import (
4
4
"fmt"
5
- . "launchpad.net/gocheck "
5
+ "testing "
6
6
)
7
7
8
- type MiddlewareTestSuite struct {}
9
-
10
- var _ = Suite (& MiddlewareTestSuite {})
11
-
12
8
func (c * Context ) A (w ResponseWriter , r * Request ) {
13
9
fmt .Fprintf (w , "context-A" )
14
10
}
@@ -73,36 +69,36 @@ func mwGenricInterface(ctx interface{}, w ResponseWriter, r *Request, next NextM
73
69
next (w , r )
74
70
}
75
71
76
- func ( s * MiddlewareTestSuite ) TestFlatNoMiddleware (c * C ) {
72
+ func TestFlatNoMiddleware (t * testing. T ) {
77
73
router := New (Context {})
78
74
router .Get ("/action" , (* Context ).A )
79
75
router .Get ("/action_z" , (* Context ).Z )
80
76
81
77
rw , req := newTestRequest ("GET" , "/action" )
82
78
router .ServeHTTP (rw , req )
83
- assertResponse (c , rw , "context-A" , 200 )
79
+ assertResponse (t , rw , "context-A" , 200 )
84
80
85
81
rw , req = newTestRequest ("GET" , "/action_z" )
86
82
router .ServeHTTP (rw , req )
87
- assertResponse (c , rw , "context-Z" , 200 )
83
+ assertResponse (t , rw , "context-Z" , 200 )
88
84
}
89
85
90
- func ( s * MiddlewareTestSuite ) TestFlatOneMiddleware (c * C ) {
86
+ func TestFlatOneMiddleware (t * testing. T ) {
91
87
router := New (Context {})
92
88
router .Middleware ((* Context ).mwAlpha )
93
89
router .Get ("/action" , (* Context ).A )
94
90
router .Get ("/action_z" , (* Context ).Z )
95
91
96
92
rw , req := newTestRequest ("GET" , "/action" )
97
93
router .ServeHTTP (rw , req )
98
- assertResponse (c , rw , "context-mw-Alpha context-A" , 200 )
94
+ assertResponse (t , rw , "context-mw-Alpha context-A" , 200 )
99
95
100
96
rw , req = newTestRequest ("GET" , "/action_z" )
101
97
router .ServeHTTP (rw , req )
102
- assertResponse (c , rw , "context-mw-Alpha context-Z" , 200 )
98
+ assertResponse (t , rw , "context-mw-Alpha context-Z" , 200 )
103
99
}
104
100
105
- func ( s * MiddlewareTestSuite ) TestFlatTwoMiddleware (c * C ) {
101
+ func TestFlatTwoMiddleware (t * testing. T ) {
106
102
router := New (Context {})
107
103
router .Middleware ((* Context ).mwAlpha )
108
104
router .Middleware ((* Context ).mwBeta )
@@ -111,14 +107,14 @@ func (s *MiddlewareTestSuite) TestFlatTwoMiddleware(c *C) {
111
107
112
108
rw , req := newTestRequest ("GET" , "/action" )
113
109
router .ServeHTTP (rw , req )
114
- assertResponse (c , rw , "context-mw-Alpha context-mw-Beta context-A" , 200 )
110
+ assertResponse (t , rw , "context-mw-Alpha context-mw-Beta context-A" , 200 )
115
111
116
112
rw , req = newTestRequest ("GET" , "/action_z" )
117
113
router .ServeHTTP (rw , req )
118
- assertResponse (c , rw , "context-mw-Alpha context-mw-Beta context-Z" , 200 )
114
+ assertResponse (t , rw , "context-mw-Alpha context-mw-Beta context-Z" , 200 )
119
115
}
120
116
121
- func ( s * MiddlewareTestSuite ) TestDualTree (c * C ) {
117
+ func TestDualTree (t * testing. T ) {
122
118
router := New (Context {})
123
119
router .Middleware ((* Context ).mwAlpha )
124
120
router .Get ("/action" , (* Context ).A )
@@ -131,18 +127,18 @@ func (s *MiddlewareTestSuite) TestDualTree(c *C) {
131
127
132
128
rw , req := newTestRequest ("GET" , "/action" )
133
129
router .ServeHTTP (rw , req )
134
- assertResponse (c , rw , "context-mw-Alpha context-A" , 200 )
130
+ assertResponse (t , rw , "context-mw-Alpha context-A" , 200 )
135
131
136
132
rw , req = newTestRequest ("GET" , "/admin/action" )
137
133
router .ServeHTTP (rw , req )
138
- assertResponse (c , rw , "context-mw-Alpha admin-mw-Epsilon admin-B" , 200 )
134
+ assertResponse (t , rw , "context-mw-Alpha admin-mw-Epsilon admin-B" , 200 )
139
135
140
136
rw , req = newTestRequest ("GET" , "/api/action" )
141
137
router .ServeHTTP (rw , req )
142
- assertResponse (c , rw , "context-mw-Alpha api-mw-Delta api-C" , 200 )
138
+ assertResponse (t , rw , "context-mw-Alpha api-mw-Delta api-C" , 200 )
143
139
}
144
140
145
- func ( s * MiddlewareTestSuite ) TestDualLeaningLeftTree (c * C ) {
141
+ func TestDualLeaningLeftTree (t * testing. T ) {
146
142
router := New (Context {})
147
143
router .Get ("/action" , (* Context ).A )
148
144
admin := router .Subrouter (AdminContext {}, "/admin" )
@@ -153,18 +149,18 @@ func (s *MiddlewareTestSuite) TestDualLeaningLeftTree(c *C) {
153
149
154
150
rw , req := newTestRequest ("GET" , "/action" )
155
151
router .ServeHTTP (rw , req )
156
- assertResponse (c , rw , "context-A" , 200 )
152
+ assertResponse (t , rw , "context-A" , 200 )
157
153
158
154
rw , req = newTestRequest ("GET" , "/admin/action" )
159
155
router .ServeHTTP (rw , req )
160
- assertResponse (c , rw , "admin-B" , 200 )
156
+ assertResponse (t , rw , "admin-B" , 200 )
161
157
162
158
rw , req = newTestRequest ("GET" , "/api/action" )
163
159
router .ServeHTTP (rw , req )
164
- assertResponse (c , rw , "api-mw-Delta api-C" , 200 )
160
+ assertResponse (t , rw , "api-mw-Delta api-C" , 200 )
165
161
}
166
162
167
- func ( s * MiddlewareTestSuite ) TestTicketsA (c * C ) {
163
+ func TestTicketsA (t * testing. T ) {
168
164
router := New (Context {})
169
165
admin := router .Subrouter (AdminContext {}, "/admin" )
170
166
admin .Middleware ((* AdminContext ).mwEpsilon )
@@ -173,10 +169,10 @@ func (s *MiddlewareTestSuite) TestTicketsA(c *C) {
173
169
174
170
rw , req := newTestRequest ("GET" , "/admin/tickets/action" )
175
171
router .ServeHTTP (rw , req )
176
- assertResponse (c , rw , "admin-mw-Epsilon tickets-D" , 200 )
172
+ assertResponse (t , rw , "admin-mw-Epsilon tickets-D" , 200 )
177
173
}
178
174
179
- func ( s * MiddlewareTestSuite ) TestTicketsB (c * C ) {
175
+ func TestTicketsB (t * testing. T ) {
180
176
router := New (Context {})
181
177
admin := router .Subrouter (AdminContext {}, "/admin" )
182
178
tickets := admin .Subrouter (TicketsContext {}, "/tickets" )
@@ -185,10 +181,10 @@ func (s *MiddlewareTestSuite) TestTicketsB(c *C) {
185
181
186
182
rw , req := newTestRequest ("GET" , "/admin/tickets/action" )
187
183
router .ServeHTTP (rw , req )
188
- assertResponse (c , rw , "tickets-mw-Eta tickets-D" , 200 )
184
+ assertResponse (t , rw , "tickets-mw-Eta tickets-D" , 200 )
189
185
}
190
186
191
- func ( s * MiddlewareTestSuite ) TestTicketsC (c * C ) {
187
+ func TestTicketsC (t * testing. T ) {
192
188
router := New (Context {})
193
189
router .Middleware ((* Context ).mwAlpha )
194
190
admin := router .Subrouter (AdminContext {}, "/admin" )
@@ -197,10 +193,10 @@ func (s *MiddlewareTestSuite) TestTicketsC(c *C) {
197
193
198
194
rw , req := newTestRequest ("GET" , "/admin/tickets/action" )
199
195
router .ServeHTTP (rw , req )
200
- assertResponse (c , rw , "context-mw-Alpha tickets-D" , 200 )
196
+ assertResponse (t , rw , "context-mw-Alpha tickets-D" , 200 )
201
197
}
202
198
203
- func ( s * MiddlewareTestSuite ) TestTicketsD (c * C ) {
199
+ func TestTicketsD (t * testing. T ) {
204
200
router := New (Context {})
205
201
router .Middleware ((* Context ).mwAlpha )
206
202
admin := router .Subrouter (AdminContext {}, "/admin" )
@@ -210,10 +206,10 @@ func (s *MiddlewareTestSuite) TestTicketsD(c *C) {
210
206
211
207
rw , req := newTestRequest ("GET" , "/admin/tickets/action" )
212
208
router .ServeHTTP (rw , req )
213
- assertResponse (c , rw , "context-mw-Alpha tickets-mw-Eta tickets-D" , 200 )
209
+ assertResponse (t , rw , "context-mw-Alpha tickets-mw-Eta tickets-D" , 200 )
214
210
}
215
211
216
- func ( s * MiddlewareTestSuite ) TestTicketsE (c * C ) {
212
+ func TestTicketsE (t * testing. T ) {
217
213
router := New (Context {})
218
214
router .Middleware ((* Context ).mwAlpha )
219
215
router .Middleware ((* Context ).mwBeta )
@@ -227,20 +223,20 @@ func (s *MiddlewareTestSuite) TestTicketsE(c *C) {
227
223
228
224
rw , req := newTestRequest ("GET" , "/admin/tickets/action" )
229
225
router .ServeHTTP (rw , req )
230
- assertResponse (c , rw , "context-mw-Alpha context-mw-Beta context-mw-Gamma admin-mw-Epsilon admin-mw-Zeta tickets-mw-Eta tickets-D" , 200 )
226
+ assertResponse (t , rw , "context-mw-Alpha context-mw-Beta context-mw-Gamma admin-mw-Epsilon admin-mw-Zeta tickets-mw-Eta tickets-D" , 200 )
231
227
}
232
228
233
- func ( s * MiddlewareTestSuite ) TestNoNext (c * C ) {
229
+ func TestNoNext (t * testing. T ) {
234
230
router := New (Context {})
235
231
router .Middleware ((* Context ).mwNoNext )
236
232
router .Get ("/action" , (* Context ).A )
237
233
238
234
rw , req := newTestRequest ("GET" , "/action" )
239
235
router .ServeHTTP (rw , req )
240
- assertResponse (c , rw , "context-mw-NoNext" , 200 )
236
+ assertResponse (t , rw , "context-mw-NoNext" , 200 )
241
237
}
242
238
243
- func ( s * MiddlewareTestSuite ) TestSameContext (c * C ) {
239
+ func TestSameContext (t * testing. T ) {
244
240
router := New (Context {})
245
241
router .Middleware ((* Context ).mwAlpha ).
246
242
Middleware ((* Context ).mwBeta )
@@ -250,25 +246,25 @@ func (s *MiddlewareTestSuite) TestSameContext(c *C) {
250
246
251
247
rw , req := newTestRequest ("GET" , "/admin/foo" )
252
248
router .ServeHTTP (rw , req )
253
- assertResponse (c , rw , "context-mw-Alpha context-mw-Beta context-mw-Gamma context-A" , 200 )
249
+ assertResponse (t , rw , "context-mw-Alpha context-mw-Beta context-mw-Gamma context-A" , 200 )
254
250
}
255
251
256
- func ( s * MiddlewareTestSuite ) TestSameNamespace (c * C ) {
252
+ func TestSameNamespace (t * testing. T ) {
257
253
router := New (Context {})
258
254
admin := router .Subrouter (AdminContext {}, "/" )
259
255
admin .Get ("/action" , (* AdminContext ).B )
260
256
261
257
rw , req := newTestRequest ("GET" , "/action" )
262
258
router .ServeHTTP (rw , req )
263
- assertResponse (c , rw , "admin-B" , 200 )
259
+ assertResponse (t , rw , "admin-B" , 200 )
264
260
}
265
261
266
- func ( s * MiddlewareTestSuite ) TestInterfaceMiddleware (c * C ) {
262
+ func TestInterfaceMiddleware (t * testing. T ) {
267
263
router := New (Context {})
268
264
router .Middleware (mwGenricInterface )
269
265
router .Get ("/action" , (* Context ).A )
270
266
271
267
rw , req := newTestRequest ("GET" , "/action" )
272
268
router .ServeHTTP (rw , req )
273
- assertResponse (c , rw , "context-mw-Interface context-A" , 200 )
269
+ assertResponse (t , rw , "context-mw-Interface context-A" , 200 )
274
270
}
0 commit comments