forked from gofiber/fiber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router_test.go
754 lines (595 loc) · 18.4 KB
/
router_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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
// ⚡️ Fiber is an Express inspired web framework written in Go with ☕️
// 📃 Github Repository: https://github.com/gofiber/fiber
// 📌 API Documentation: https://docs.gofiber.io
package fiber
import (
"encoding/json"
"errors"
"fmt"
"io"
"net/http/httptest"
"os"
"testing"
"github.com/gofiber/utils/v2"
"github.com/stretchr/testify/require"
"github.com/valyala/fasthttp"
)
var routesFixture routeJSON
func init() {
dat, err := os.ReadFile("./.github/testdata/testRoutes.json")
if err != nil {
panic(err)
}
if err := json.Unmarshal(dat, &routesFixture); err != nil {
panic(err)
}
}
func Test_Route_Match_SameLength(t *testing.T) {
t.Parallel()
app := New()
app.Get("/:param", func(c Ctx) error {
return c.SendString(c.Params("param"))
})
resp, err := app.Test(httptest.NewRequest(MethodGet, "/:param", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, 200, resp.StatusCode, "Status code")
body, err := io.ReadAll(resp.Body)
require.NoError(t, err, "app.Test(req)")
require.Equal(t, ":param", app.getString(body))
// with param
resp, err = app.Test(httptest.NewRequest(MethodGet, "/test", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, 200, resp.StatusCode, "Status code")
body, err = io.ReadAll(resp.Body)
require.NoError(t, err, "app.Test(req)")
require.Equal(t, "test", app.getString(body))
}
func Test_Route_Match_Star(t *testing.T) {
t.Parallel()
app := New()
app.Get("/*", func(c Ctx) error {
return c.SendString(c.Params("*"))
})
resp, err := app.Test(httptest.NewRequest(MethodGet, "/*", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, 200, resp.StatusCode, "Status code")
body, err := io.ReadAll(resp.Body)
require.NoError(t, err, "app.Test(req)")
require.Equal(t, "*", app.getString(body))
// with param
resp, err = app.Test(httptest.NewRequest(MethodGet, "/test", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, 200, resp.StatusCode, "Status code")
body, err = io.ReadAll(resp.Body)
require.NoError(t, err, "app.Test(req)")
require.Equal(t, "test", app.getString(body))
// without parameter
route := Route{
star: true,
path: "/*",
routeParser: routeParser{},
}
params := [maxParams]string{}
match := route.match("", "", ¶ms)
require.True(t, match)
require.Equal(t, [maxParams]string{}, params)
// with parameter
match = route.match("/favicon.ico", "/favicon.ico", ¶ms)
require.True(t, match)
require.Equal(t, [maxParams]string{"favicon.ico"}, params)
// without parameter again
match = route.match("", "", ¶ms)
require.True(t, match)
require.Equal(t, [maxParams]string{}, params)
}
func Test_Route_Match_Root(t *testing.T) {
t.Parallel()
app := New()
app.Get("/", func(c Ctx) error {
return c.SendString("root")
})
resp, err := app.Test(httptest.NewRequest(MethodGet, "/", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, 200, resp.StatusCode, "Status code")
body, err := io.ReadAll(resp.Body)
require.NoError(t, err, "app.Test(req)")
require.Equal(t, "root", app.getString(body))
}
func Test_Route_Match_Parser(t *testing.T) {
t.Parallel()
app := New()
app.Get("/foo/:ParamName", func(c Ctx) error {
return c.SendString(c.Params("ParamName"))
})
app.Get("/Foobar/*", func(c Ctx) error {
return c.SendString(c.Params("*"))
})
resp, err := app.Test(httptest.NewRequest(MethodGet, "/foo/bar", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, 200, resp.StatusCode, "Status code")
body, err := io.ReadAll(resp.Body)
require.NoError(t, err, "app.Test(req)")
require.Equal(t, "bar", app.getString(body))
// with star
resp, err = app.Test(httptest.NewRequest(MethodGet, "/Foobar/test", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, 200, resp.StatusCode, "Status code")
body, err = io.ReadAll(resp.Body)
require.NoError(t, err, "app.Test(req)")
require.Equal(t, "test", app.getString(body))
}
func Test_Route_Match_Middleware(t *testing.T) {
t.Parallel()
app := New()
app.Use("/foo/*", func(c Ctx) error {
return c.SendString(c.Params("*"))
})
resp, err := app.Test(httptest.NewRequest(MethodGet, "/foo/*", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, 200, resp.StatusCode, "Status code")
body, err := io.ReadAll(resp.Body)
require.NoError(t, err, "app.Test(req)")
require.Equal(t, "*", app.getString(body))
// with param
resp, err = app.Test(httptest.NewRequest(MethodGet, "/foo/bar/fasel", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, 200, resp.StatusCode, "Status code")
body, err = io.ReadAll(resp.Body)
require.NoError(t, err, "app.Test(req)")
require.Equal(t, "bar/fasel", app.getString(body))
}
func Test_Route_Match_UnescapedPath(t *testing.T) {
t.Parallel()
app := New(Config{UnescapePath: true})
app.Use("/créer", func(c Ctx) error {
return c.SendString("test")
})
resp, err := app.Test(httptest.NewRequest(MethodGet, "/cr%C3%A9er", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, StatusOK, resp.StatusCode, "Status code")
body, err := io.ReadAll(resp.Body)
require.NoError(t, err, "app.Test(req)")
require.Equal(t, "test", app.getString(body))
// without special chars
resp, err = app.Test(httptest.NewRequest(MethodGet, "/créer", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, StatusOK, resp.StatusCode, "Status code")
// check deactivated behavior
app.config.UnescapePath = false
resp, err = app.Test(httptest.NewRequest(MethodGet, "/cr%C3%A9er", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, StatusNotFound, resp.StatusCode, "Status code")
}
func Test_Route_Match_WithEscapeChar(t *testing.T) {
t.Parallel()
app := New()
// static route and escaped part
app.Get("/v1/some/resource/name\\:customVerb", func(c Ctx) error {
return c.SendString("static")
})
// group route
group := app.Group("/v2/\\:firstVerb")
group.Get("/\\:customVerb", func(c Ctx) error {
return c.SendString("group")
})
// route with resource param and escaped part
app.Get("/v3/:resource/name\\:customVerb", func(c Ctx) error {
return c.SendString(c.Params("resource"))
})
// check static route
resp, err := app.Test(httptest.NewRequest(MethodGet, "/v1/some/resource/name:customVerb", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, StatusOK, resp.StatusCode, "Status code")
body, err := io.ReadAll(resp.Body)
require.NoError(t, err, "app.Test(req)")
require.Equal(t, "static", app.getString(body))
// check group route
resp, err = app.Test(httptest.NewRequest(MethodGet, "/v2/:firstVerb/:customVerb", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, StatusOK, resp.StatusCode, "Status code")
body, err = io.ReadAll(resp.Body)
require.NoError(t, err, "app.Test(req)")
require.Equal(t, "group", app.getString(body))
// check param route
resp, err = app.Test(httptest.NewRequest(MethodGet, "/v3/awesome/name:customVerb", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, StatusOK, resp.StatusCode, "Status code")
body, err = io.ReadAll(resp.Body)
require.NoError(t, err, "app.Test(req)")
require.Equal(t, "awesome", app.getString(body))
}
func Test_Route_Match_Middleware_HasPrefix(t *testing.T) {
t.Parallel()
app := New()
app.Use("/foo", func(c Ctx) error {
return c.SendString("middleware")
})
resp, err := app.Test(httptest.NewRequest(MethodGet, "/foo/bar", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, 200, resp.StatusCode, "Status code")
body, err := io.ReadAll(resp.Body)
require.NoError(t, err, "app.Test(req)")
require.Equal(t, "middleware", app.getString(body))
}
func Test_Route_Match_Middleware_Root(t *testing.T) {
t.Parallel()
app := New()
app.Use("/", func(c Ctx) error {
return c.SendString("middleware")
})
resp, err := app.Test(httptest.NewRequest(MethodGet, "/everything", nil))
require.NoError(t, err, "app.Test(req)")
require.Equal(t, 200, resp.StatusCode, "Status code")
body, err := io.ReadAll(resp.Body)
require.NoError(t, err, "app.Test(req)")
require.Equal(t, "middleware", app.getString(body))
}
func Test_Router_Register_Missing_Handler(t *testing.T) {
t.Parallel()
app := New()
defer func() {
if err := recover(); err != nil {
require.Equal(t, "missing handler/middleware in route: /doe\n", fmt.Sprintf("%v", err))
}
}()
app.register([]string{"USE"}, "/doe", nil, nil)
}
func Test_Ensure_Router_Interface_Implementation(t *testing.T) {
t.Parallel()
var app any = (*App)(nil)
_, ok := app.(Router)
require.True(t, ok)
var group any = (*Group)(nil)
_, ok = group.(Router)
require.True(t, ok)
}
func Test_Router_Handler_Catch_Error(t *testing.T) {
t.Parallel()
app := New()
app.config.ErrorHandler = func(_ Ctx, _ error) error {
return errors.New("fake error")
}
app.Get("/", func(_ Ctx) error {
return ErrForbidden
})
c := &fasthttp.RequestCtx{}
app.Handler()(c)
require.Equal(t, StatusInternalServerError, c.Response.Header.StatusCode())
}
func Test_Router_NotFound(t *testing.T) {
t.Parallel()
app := New()
app.Use(func(c Ctx) error {
return c.Next()
})
appHandler := app.Handler()
c := &fasthttp.RequestCtx{}
c.Request.Header.SetMethod("DELETE")
c.URI().SetPath("/this/route/does/not/exist")
appHandler(c)
require.Equal(t, 404, c.Response.StatusCode())
require.Equal(t, "Cannot DELETE /this/route/does/not/exist", string(c.Response.Body()))
}
func Test_Router_NotFound_HTML_Inject(t *testing.T) {
t.Parallel()
app := New()
app.Use(func(c Ctx) error {
return c.Next()
})
appHandler := app.Handler()
c := &fasthttp.RequestCtx{}
c.Request.Header.SetMethod("DELETE")
c.URI().SetPath("/does/not/exist<script>alert('foo');</script>")
appHandler(c)
require.Equal(t, 404, c.Response.StatusCode())
require.Equal(t, "Cannot DELETE /does/not/exist<script>alert('foo');</script>", string(c.Response.Body()))
}
//////////////////////////////////////////////
///////////////// BENCHMARKS /////////////////
//////////////////////////////////////////////
func registerDummyRoutes(app *App) {
h := func(_ Ctx) error {
return nil
}
for _, r := range routesFixture.GithubAPI {
app.Add([]string{r.Method}, r.Path, h)
}
}
// go test -v -run=^$ -bench=Benchmark_App_MethodNotAllowed -benchmem -count=4
func Benchmark_App_MethodNotAllowed(b *testing.B) {
app := New()
h := func(c Ctx) error {
return c.SendString("Hello World!")
}
app.All("/this/is/a/", h)
app.Get("/this/is/a/dummy/route/oke", h)
appHandler := app.Handler()
c := &fasthttp.RequestCtx{}
c.Request.Header.SetMethod("DELETE")
c.URI().SetPath("/this/is/a/dummy/route/oke")
b.ResetTimer()
for n := 0; n < b.N; n++ {
appHandler(c)
}
b.StopTimer()
require.Equal(b, 405, c.Response.StatusCode())
require.Equal(b, MethodGet, string(c.Response.Header.Peek("Allow")))
require.Equal(b, utils.StatusMessage(StatusMethodNotAllowed), string(c.Response.Body()))
}
// go test -v ./... -run=^$ -bench=Benchmark_Router_NotFound -benchmem -count=4
func Benchmark_Router_NotFound(b *testing.B) {
app := New()
app.Use(func(c Ctx) error {
return c.Next()
})
registerDummyRoutes(app)
appHandler := app.Handler()
c := &fasthttp.RequestCtx{}
c.Request.Header.SetMethod("DELETE")
c.URI().SetPath("/this/route/does/not/exist")
b.ResetTimer()
for n := 0; n < b.N; n++ {
appHandler(c)
}
require.Equal(b, 404, c.Response.StatusCode())
require.Equal(b, "Cannot DELETE /this/route/does/not/exist", string(c.Response.Body()))
}
// go test -v ./... -run=^$ -bench=Benchmark_Router_Handler -benchmem -count=4
func Benchmark_Router_Handler(b *testing.B) {
app := New()
registerDummyRoutes(app)
appHandler := app.Handler()
c := &fasthttp.RequestCtx{}
c.Request.Header.SetMethod("DELETE")
c.URI().SetPath("/user/keys/1337")
b.ResetTimer()
for n := 0; n < b.N; n++ {
appHandler(c)
}
}
func Benchmark_Router_Handler_Strict_Case(b *testing.B) {
app := New(Config{
StrictRouting: true,
CaseSensitive: true,
})
registerDummyRoutes(app)
appHandler := app.Handler()
c := &fasthttp.RequestCtx{}
c.Request.Header.SetMethod("DELETE")
c.URI().SetPath("/user/keys/1337")
b.ResetTimer()
for n := 0; n < b.N; n++ {
appHandler(c)
}
}
// go test -v ./... -run=^$ -bench=Benchmark_Router_Chain -benchmem -count=4
func Benchmark_Router_Chain(b *testing.B) {
app := New()
handler := func(c Ctx) error {
return c.Next()
}
app.Get("/", handler, handler, handler, handler, handler, handler)
appHandler := app.Handler()
c := &fasthttp.RequestCtx{}
c.Request.Header.SetMethod(MethodGet)
c.URI().SetPath("/")
b.ResetTimer()
for n := 0; n < b.N; n++ {
appHandler(c)
}
}
// go test -v ./... -run=^$ -bench=Benchmark_Router_WithCompression -benchmem -count=4
func Benchmark_Router_WithCompression(b *testing.B) {
app := New()
handler := func(c Ctx) error {
return c.Next()
}
app.Get("/", handler)
app.Get("/", handler)
app.Get("/", handler)
app.Get("/", handler)
app.Get("/", handler)
app.Get("/", handler)
appHandler := app.Handler()
c := &fasthttp.RequestCtx{}
c.Request.Header.SetMethod(MethodGet)
c.URI().SetPath("/")
b.ResetTimer()
for n := 0; n < b.N; n++ {
appHandler(c)
}
}
// go test -run=^$ -bench=Benchmark_Startup_Process -benchmem -count=9
func Benchmark_Startup_Process(b *testing.B) {
for n := 0; n < b.N; n++ {
app := New()
registerDummyRoutes(app)
app.startupProcess()
}
}
// go test -v ./... -run=^$ -bench=Benchmark_Router_Next -benchmem -count=4
func Benchmark_Router_Next(b *testing.B) {
app := New()
registerDummyRoutes(app)
app.startupProcess()
request := &fasthttp.RequestCtx{}
request.Request.Header.SetMethod("DELETE")
request.URI().SetPath("/user/keys/1337")
var res bool
var err error
c := app.AcquireCtx(request).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed
b.ResetTimer()
for n := 0; n < b.N; n++ {
c.indexRoute = -1
res, err = app.next(c)
}
require.NoError(b, err)
require.True(b, res)
require.Equal(b, 4, c.indexRoute)
}
// go test -v ./... -run=^$ -bench=Benchmark_Router_Next_Default -benchmem -count=4
func Benchmark_Router_Next_Default(b *testing.B) {
app := New()
app.Get("/", func(_ Ctx) error {
return nil
})
h := app.Handler()
fctx := &fasthttp.RequestCtx{}
fctx.Request.Header.SetMethod(MethodGet)
fctx.Request.SetRequestURI("/")
b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
h(fctx)
}
}
// go test -v ./... -run=^$ -bench=Benchmark_Route_Match -benchmem -count=4
func Benchmark_Route_Match(b *testing.B) {
var match bool
var params [maxParams]string
parsed := parseRoute("/user/keys/:id")
route := &Route{
use: false,
root: false,
star: false,
routeParser: parsed,
Params: parsed.params,
path: "/user/keys/:id",
Path: "/user/keys/:id",
Method: "DELETE",
}
route.Handlers = append(route.Handlers, func(_ Ctx) error {
return nil
})
b.ResetTimer()
for n := 0; n < b.N; n++ {
match = route.match("/user/keys/1337", "/user/keys/1337", ¶ms)
}
require.True(b, match)
require.Equal(b, []string{"1337"}, params[0:len(parsed.params)])
}
// go test -v ./... -run=^$ -bench=Benchmark_Route_Match_Star -benchmem -count=4
func Benchmark_Route_Match_Star(b *testing.B) {
var match bool
var params [maxParams]string
parsed := parseRoute("/*")
route := &Route{
use: false,
root: false,
star: true,
routeParser: parsed,
Params: parsed.params,
path: "/user/keys/bla",
Path: "/user/keys/bla",
Method: "DELETE",
}
route.Handlers = append(route.Handlers, func(_ Ctx) error {
return nil
})
b.ResetTimer()
for n := 0; n < b.N; n++ {
match = route.match("/user/keys/bla", "/user/keys/bla", ¶ms)
}
require.True(b, match)
require.Equal(b, []string{"user/keys/bla"}, params[0:len(parsed.params)])
}
// go test -v ./... -run=^$ -bench=Benchmark_Route_Match_Root -benchmem -count=4
func Benchmark_Route_Match_Root(b *testing.B) {
var match bool
var params [maxParams]string
parsed := parseRoute("/")
route := &Route{
use: false,
root: true,
star: false,
path: "/",
routeParser: parsed,
Params: parsed.params,
Path: "/",
Method: "DELETE",
}
route.Handlers = append(route.Handlers, func(_ Ctx) error {
return nil
})
b.ResetTimer()
for n := 0; n < b.N; n++ {
match = route.match("/", "/", ¶ms)
}
require.True(b, match)
require.Equal(b, []string{}, params[0:len(parsed.params)])
}
// go test -v ./... -run=^$ -bench=Benchmark_Router_Handler_CaseSensitive -benchmem -count=4
func Benchmark_Router_Handler_CaseSensitive(b *testing.B) {
app := New()
app.config.CaseSensitive = true
registerDummyRoutes(app)
appHandler := app.Handler()
c := &fasthttp.RequestCtx{}
c.Request.Header.SetMethod("DELETE")
c.URI().SetPath("/user/keys/1337")
b.ResetTimer()
for n := 0; n < b.N; n++ {
appHandler(c)
}
}
// go test -v ./... -run=^$ -bench=Benchmark_Router_Handler_Unescape -benchmem -count=4
func Benchmark_Router_Handler_Unescape(b *testing.B) {
app := New()
app.config.UnescapePath = true
registerDummyRoutes(app)
app.Delete("/créer", func(_ Ctx) error {
return nil
})
appHandler := app.Handler()
c := &fasthttp.RequestCtx{}
c.Request.Header.SetMethod(MethodDelete)
c.URI().SetPath("/cr%C3%A9er")
b.ResetTimer()
for n := 0; n < b.N; n++ {
c.URI().SetPath("/cr%C3%A9er")
appHandler(c)
}
}
// go test -run=^$ -bench=Benchmark_Router_Handler_StrictRouting -benchmem -count=4
func Benchmark_Router_Handler_StrictRouting(b *testing.B) {
app := New()
app.config.CaseSensitive = true
registerDummyRoutes(app)
appHandler := app.Handler()
c := &fasthttp.RequestCtx{}
c.Request.Header.SetMethod("DELETE")
c.URI().SetPath("/user/keys/1337")
b.ResetTimer()
for n := 0; n < b.N; n++ {
appHandler(c)
}
}
// go test -run=^$ -bench=Benchmark_Router_Github_API -benchmem -count=16
func Benchmark_Router_Github_API(b *testing.B) {
app := New()
registerDummyRoutes(app)
app.startupProcess()
c := &fasthttp.RequestCtx{}
var match bool
var err error
b.ResetTimer()
for i := range routesFixture.TestRoutes {
c.Request.Header.SetMethod(routesFixture.TestRoutes[i].Method)
for n := 0; n < b.N; n++ {
c.URI().SetPath(routesFixture.TestRoutes[i].Path)
ctx := app.AcquireCtx(c).(*DefaultCtx) //nolint:errcheck, forcetypeassert // not needed
match, err = app.next(ctx)
app.ReleaseCtx(ctx)
}
require.NoError(b, err)
require.True(b, match)
}
}
type testRoute struct {
Method string `json:"method"`
Path string `json:"path"`
}
type routeJSON struct {
TestRoutes []testRoute `json:"test_routes"`
GithubAPI []testRoute `json:"github_api"`
}