diff --git a/redis_test.go b/redis_test.go index 4cbc3899..ec7ba7e7 100644 --- a/redis_test.go +++ b/redis_test.go @@ -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", + })) + }) +})