@@ -28,6 +28,43 @@ func testStatus200(t *testing.T, app *App, url string, method string) {
28
28
29
29
// }
30
30
31
+ // func Test_App_ErrorHandler(t *testing.T) {
32
+ // app := New()
33
+
34
+ // app.Get("/", func(c *Ctx) {
35
+ // c.Next(errors.New("Hi, I'm an error!"))
36
+ // })
37
+
38
+ // resp, err := app.Test(httptest.NewRequest("GET", "/", nil))
39
+ // utils.AssertEqual(t, nil, err, "app.Test(req)")
40
+ // utils.AssertEqual(t, 500, resp.StatusCode, "Status code")
41
+
42
+ // body, err := ioutil.ReadAll(resp.Body)
43
+ // utils.AssertEqual(t, nil, err)
44
+ // utils.AssertEqual(t, "Hi, I'm an error!", string(body))
45
+
46
+ // }
47
+
48
+ // func Test_App_ErrorHandler_Custom(t *testing.T) {
49
+ // app := New(&Settings{
50
+ // ErrorHandler: func(ctx *Ctx, err error) {
51
+ // ctx.Status(200).SendString("Hi, I'm an custom error!")
52
+ // },
53
+ // })
54
+
55
+ // app.Get("/", func(c *Ctx) {
56
+ // c.Next(errors.New("Hi, I'm an error!"))
57
+ // })
58
+
59
+ // resp, err := app.Test(httptest.NewRequest("GET", "/", nil))
60
+ // utils.AssertEqual(t, nil, err, "app.Test(req)")
61
+ // utils.AssertEqual(t, 200, resp.StatusCode, "Status code")
62
+
63
+ // body, err := ioutil.ReadAll(resp.Body)
64
+ // utils.AssertEqual(t, nil, err)
65
+ // utils.AssertEqual(t, "Hi, I'm an custom error!", string(body))
66
+ // }
67
+
31
68
func Test_App_Nested_Params (t * testing.T ) {
32
69
app := New ()
33
70
@@ -204,8 +241,8 @@ func Test_App_Shutdown(t *testing.T) {
204
241
_ = app .Shutdown ()
205
242
}
206
243
207
- // go test -run Test_App_Static
208
- func Test_App_Static_Index (t * testing.T ) {
244
+ // go test -run Test_App_Static_Index_Default
245
+ func Test_App_Static_Index_Default (t * testing.T ) {
209
246
app := New ()
210
247
211
248
app .Static ("/prefix" , "./.github/workflows" )
@@ -222,6 +259,33 @@ func Test_App_Static_Index(t *testing.T) {
222
259
utils .AssertEqual (t , true , strings .Contains (string (body ), "Hello, World!" ))
223
260
224
261
}
262
+
263
+ // go test -run Test_App_Static_Index
264
+ func Test_App_Static_Direct (t * testing.T ) {
265
+ app := New ()
266
+
267
+ app .Static ("/" , "./.github" )
268
+
269
+ resp , err := app .Test (httptest .NewRequest ("GET" , "/index.html" , nil ))
270
+ utils .AssertEqual (t , nil , err , "app.Test(req)" )
271
+ utils .AssertEqual (t , 200 , resp .StatusCode , "Status code" )
272
+ utils .AssertEqual (t , false , resp .Header .Get ("Content-Length" ) == "" )
273
+ utils .AssertEqual (t , "text/html; charset=utf-8" , resp .Header .Get ("Content-Type" ))
274
+
275
+ body , err := ioutil .ReadAll (resp .Body )
276
+ utils .AssertEqual (t , nil , err )
277
+ utils .AssertEqual (t , true , strings .Contains (string (body ), "Hello, World!" ))
278
+
279
+ resp , err = app .Test (httptest .NewRequest ("GET" , "/FUNDING.yml" , nil ))
280
+ utils .AssertEqual (t , nil , err , "app.Test(req)" )
281
+ utils .AssertEqual (t , 200 , resp .StatusCode , "Status code" )
282
+ utils .AssertEqual (t , false , resp .Header .Get ("Content-Length" ) == "" )
283
+ utils .AssertEqual (t , "text/plain; charset=utf-8" , resp .Header .Get ("Content-Type" ))
284
+
285
+ body , err = ioutil .ReadAll (resp .Body )
286
+ utils .AssertEqual (t , nil , err )
287
+ utils .AssertEqual (t , true , strings .Contains (string (body ), "buymeacoffee" ))
288
+ }
225
289
func Test_App_Static_Group (t * testing.T ) {
226
290
app := New ()
227
291
@@ -264,6 +328,10 @@ func Test_App_Static_Wildcard(t *testing.T) {
264
328
utils .AssertEqual (t , false , resp .Header .Get ("Content-Length" ) == "" )
265
329
utils .AssertEqual (t , "text/plain; charset=utf-8" , resp .Header .Get ("Content-Type" ))
266
330
331
+ body , err := ioutil .ReadAll (resp .Body )
332
+ utils .AssertEqual (t , nil , err )
333
+ utils .AssertEqual (t , true , strings .Contains (string (body ), "buymeacoffee" ))
334
+
267
335
}
268
336
269
337
func Test_App_Static_Prefix_Wildcard (t * testing.T ) {
@@ -277,6 +345,18 @@ func Test_App_Static_Prefix_Wildcard(t *testing.T) {
277
345
utils .AssertEqual (t , 200 , resp .StatusCode , "Status code" )
278
346
utils .AssertEqual (t , false , resp .Header .Get ("Content-Length" ) == "" )
279
347
utils .AssertEqual (t , "text/plain; charset=utf-8" , resp .Header .Get ("Content-Type" ))
348
+
349
+ app .Static ("/my/nameisjohn*" , "./.github/FUNDING.yml" )
350
+
351
+ resp , err = app .Test (httptest .NewRequest ("GET" , "/my/nameisjohn/no/its/not" , nil ))
352
+ utils .AssertEqual (t , nil , err , "app.Test(req)" )
353
+ utils .AssertEqual (t , 200 , resp .StatusCode , "Status code" )
354
+ utils .AssertEqual (t , false , resp .Header .Get ("Content-Length" ) == "" )
355
+ utils .AssertEqual (t , "text/plain; charset=utf-8" , resp .Header .Get ("Content-Type" ))
356
+
357
+ body , err := ioutil .ReadAll (resp .Body )
358
+ utils .AssertEqual (t , nil , err )
359
+ utils .AssertEqual (t , true , strings .Contains (string (body ), "buymeacoffee" ))
280
360
}
281
361
282
362
func Test_App_Static_Prefix (t * testing.T ) {
0 commit comments