MCPcopy
hub / github.com/redis/go-redis / TestPoolHookManager

Function TestPoolHookManager

internal/pool/hooks_test.go:37–104  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35}
36
37func TestPoolHookManager(t *testing.T) {
38 manager := NewPoolHookManager()
39
40 // Test initial state
41 if manager.GetHookCount() != 0 {
42 t.Errorf("Expected 0 hooks initially, got %d", manager.GetHookCount())
43 }
44
45 // Add hooks
46 hook1 := &TestHook{ShouldPool: true, ShouldAccept: true}
47 hook2 := &TestHook{ShouldPool: true, ShouldAccept: true}
48
49 manager.AddHook(hook1)
50 manager.AddHook(hook2)
51
52 if manager.GetHookCount() != 2 {
53 t.Errorf("Expected 2 hooks after adding, got %d", manager.GetHookCount())
54 }
55
56 // Test ProcessOnGet
57 ctx := context.Background()
58 conn := &Conn{} // Mock connection
59
60 accept, err := manager.ProcessOnGet(ctx, conn, false)
61 if err != nil {
62 t.Errorf("ProcessOnGet should not error: %v", err)
63 }
64 if !accept {
65 t.Error("Expected accept to be true")
66 }
67
68 if hook1.OnGetCalled != 1 {
69 t.Errorf("Expected hook1.OnGetCalled to be 1, got %d", hook1.OnGetCalled)
70 }
71
72 if hook2.OnGetCalled != 1 {
73 t.Errorf("Expected hook2.OnGetCalled to be 1, got %d", hook2.OnGetCalled)
74 }
75
76 // Test ProcessOnPut
77 shouldPool, shouldRemove, err := manager.ProcessOnPut(ctx, conn)
78 if err != nil {
79 t.Errorf("ProcessOnPut should not error: %v", err)
80 }
81
82 if !shouldPool {
83 t.Error("Expected shouldPool to be true")
84 }
85
86 if shouldRemove {
87 t.Error("Expected shouldRemove to be false")
88 }
89
90 if hook1.OnPutCalled != 1 {
91 t.Errorf("Expected hook1.OnPutCalled to be 1, got %d", hook1.OnPutCalled)
92 }
93
94 if hook2.OnPutCalled != 1 {

Callers

nothing calls this directly

Calls 7

GetHookCountMethod · 0.95
AddHookMethod · 0.95
ProcessOnGetMethod · 0.95
ProcessOnPutMethod · 0.95
RemoveHookMethod · 0.95
NewPoolHookManagerFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected