Skip to content

Commit 4f38f23

Browse files
committed
test: add hook fifo mode test
Signed-off-by: monkey <[email protected]>
1 parent 97697f4 commit 4f38f23

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

redis_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,3 +483,51 @@ var _ = Describe("Conn", func() {
483483
Expect(err).NotTo(HaveOccurred())
484484
})
485485
})
486+
487+
var _ = Describe("Hook", func() {
488+
var client *redis.Client
489+
490+
BeforeEach(func() {
491+
client = redis.NewClient(redisOptions())
492+
Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred())
493+
})
494+
495+
AfterEach(func() {
496+
err := client.Close()
497+
Expect(err).NotTo(HaveOccurred())
498+
})
499+
500+
It("fifo", func() {
501+
var res []string
502+
client.AddHook(&hook{
503+
processHook: func(hook redis.ProcessHook) redis.ProcessHook {
504+
return func(ctx context.Context, cmd redis.Cmder) error {
505+
res = append(res, "hook-1-process-start")
506+
err := hook(ctx, cmd)
507+
res = append(res, "hook-1-process-end")
508+
return err
509+
}
510+
},
511+
})
512+
client.AddHook(&hook{
513+
processHook: func(hook redis.ProcessHook) redis.ProcessHook {
514+
return func(ctx context.Context, cmd redis.Cmder) error {
515+
res = append(res, "hook-2-process-start")
516+
err := hook(ctx, cmd)
517+
res = append(res, "hook-2-process-end")
518+
return err
519+
}
520+
},
521+
})
522+
523+
err := client.Ping(ctx).Err()
524+
Expect(err).NotTo(HaveOccurred())
525+
526+
Expect(res).To(Equal([]string{
527+
"hook-1-process-start",
528+
"hook-2-process-start",
529+
"hook-2-process-end",
530+
"hook-1-process-end",
531+
}))
532+
})
533+
})

0 commit comments

Comments
 (0)