Skip to content

Commit 2e6a290

Browse files
committed
test: add coverage for outer middleware execution order
1 parent 76e2023 commit 2e6a290

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

handler_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,45 @@ func TestMiddlewareOrder(t *testing.T) {
5959
}
6060
}
6161

62+
func TestOuterMiddlewareOrder(t *testing.T) {
63+
b := newTestBot(t)
64+
65+
var order []string
66+
67+
b.UseOuter(func(next Handler) Handler {
68+
return func(c *Context) error {
69+
order = append(order, "outer")
70+
return next(c)
71+
}
72+
})
73+
74+
b.Use(func(next Handler) Handler {
75+
return func(c *Context) error {
76+
order = append(order, "global")
77+
return next(c)
78+
}
79+
})
80+
81+
b.on(func(c *Context) error {
82+
order = append(order, "handler")
83+
return nil
84+
})
85+
86+
b.route(context.Background(), &Update{})
87+
88+
want := []string{"outer", "global", "handler"}
89+
90+
if len(order) != len(want) {
91+
t.Fatalf("order = %v, want %v", order, want)
92+
}
93+
94+
for i := range want {
95+
if order[i] != want[i] {
96+
t.Fatalf("order = %v, want %v", order, want)
97+
}
98+
}
99+
}
100+
62101
func TestRouterHandlerErrorIsContained(t *testing.T) {
63102
b := newTestBot(t)
64103
b.on(func(c *Context) error { return errors.New("boom") })

0 commit comments

Comments
 (0)