Skip to content

Commit 2e43105

Browse files
committed
Add coverage for Route helpers
1 parent a3ed9ce commit 2e43105

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

app_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,48 @@ func Test_App_Route(t *testing.T) {
14311431
require.Equal(t, "/test/bar/", app.GetRoute("test.bar.index").Path)
14321432
}
14331433

1434+
func Test_App_Route_nilFuncPanics(t *testing.T) {
1435+
t.Parallel()
1436+
1437+
app := New()
1438+
1439+
require.PanicsWithValue(t, "route handler 'fn' cannot be nil", func() {
1440+
app.Route("/panic", nil)
1441+
})
1442+
}
1443+
1444+
func Test_Group_Route_nilFuncPanics(t *testing.T) {
1445+
t.Parallel()
1446+
1447+
app := New()
1448+
grp := app.Group("/api")
1449+
1450+
require.PanicsWithValue(t, "route handler 'fn' cannot be nil", func() {
1451+
grp.Route("/panic", nil)
1452+
})
1453+
}
1454+
1455+
func Test_Group_RouteChain_All(t *testing.T) {
1456+
t.Parallel()
1457+
1458+
app := New()
1459+
var calls []string
1460+
grp := app.Group("/api", func(c Ctx) error {
1461+
calls = append(calls, "group")
1462+
return c.Next()
1463+
})
1464+
1465+
grp.RouteChain("/users").All(func(c Ctx) error {
1466+
calls = append(calls, "routechain")
1467+
return c.SendStatus(http.StatusOK)
1468+
})
1469+
1470+
resp, err := app.Test(httptest.NewRequest(MethodGet, "/api/users", nil))
1471+
require.NoError(t, err, "app.Test(req)")
1472+
require.Equal(t, http.StatusOK, resp.StatusCode, "Status code")
1473+
require.Equal(t, []string{"group", "routechain"}, calls)
1474+
}
1475+
14341476
func Test_App_Deep_Group(t *testing.T) {
14351477
t.Parallel()
14361478
runThroughCount := 0

0 commit comments

Comments
 (0)