mirror of https://github.com/go-redis/redis.git
test: add hook fifo mode test
Signed-off-by: monkey <golang@88.com>
This commit is contained in:
parent
97697f488f
commit
4f38f2368d
|
@ -483,3 +483,51 @@ var _ = Describe("Conn", func() {
|
|||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
var _ = Describe("Hook", func() {
|
||||
var client *redis.Client
|
||||
|
||||
BeforeEach(func() {
|
||||
client = redis.NewClient(redisOptions())
|
||||
Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
err := client.Close()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
It("fifo", func() {
|
||||
var res []string
|
||||
client.AddHook(&hook{
|
||||
processHook: func(hook redis.ProcessHook) redis.ProcessHook {
|
||||
return func(ctx context.Context, cmd redis.Cmder) error {
|
||||
res = append(res, "hook-1-process-start")
|
||||
err := hook(ctx, cmd)
|
||||
res = append(res, "hook-1-process-end")
|
||||
return err
|
||||
}
|
||||
},
|
||||
})
|
||||
client.AddHook(&hook{
|
||||
processHook: func(hook redis.ProcessHook) redis.ProcessHook {
|
||||
return func(ctx context.Context, cmd redis.Cmder) error {
|
||||
res = append(res, "hook-2-process-start")
|
||||
err := hook(ctx, cmd)
|
||||
res = append(res, "hook-2-process-end")
|
||||
return err
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
err := client.Ping(ctx).Err()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Expect(res).To(Equal([]string{
|
||||
"hook-1-process-start",
|
||||
"hook-2-process-start",
|
||||
"hook-2-process-end",
|
||||
"hook-1-process-end",
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue