mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
33 lines
548 B
Go
33 lines
548 B
Go
![]() |
package hono
|
||
|
|
||
|
import "testing"
|
||
|
|
||
|
func TestChainMiddlewares(t *testing.T) {
|
||
|
result := ""
|
||
|
middlewares := []Middleware{
|
||
|
func(c *Context, next func()) {
|
||
|
result += "1"
|
||
|
next()
|
||
|
result += "1"
|
||
|
},
|
||
|
func(c *Context, next func()) {
|
||
|
result += "2"
|
||
|
next()
|
||
|
result += "2"
|
||
|
},
|
||
|
func(c *Context, next func()) {
|
||
|
result += "3"
|
||
|
next()
|
||
|
result += "3"
|
||
|
},
|
||
|
}
|
||
|
m := ChainMiddlewares(middlewares...)
|
||
|
m(nil, func() {
|
||
|
result += "0"
|
||
|
})
|
||
|
const want = "1230321"
|
||
|
if result != want {
|
||
|
t.Errorf("result: got %q, want %q", result, want)
|
||
|
}
|
||
|
}
|