@@ -17,11 +17,12 @@ type TestHook struct {
1717 PutError error
1818 ShouldPool bool
1919 ShouldRemove bool
20+ ShouldAccept bool
2021}
2122
22- func (th * TestHook ) OnGet (ctx context.Context , conn * Conn , isNewConn bool ) error {
23+ func (th * TestHook ) OnGet (ctx context.Context , conn * Conn , isNewConn bool ) ( bool , error ) {
2324 th .OnGetCalled ++
24- return th .GetError
25+ return th .ShouldAccept , th . GetError
2526}
2627
2728func (th * TestHook ) OnPut (ctx context.Context , conn * Conn ) (shouldPool bool , shouldRemove bool , err error ) {
@@ -42,8 +43,8 @@ func TestPoolHookManager(t *testing.T) {
4243 }
4344
4445 // Add hooks
45- hook1 := & TestHook {ShouldPool : true }
46- hook2 := & TestHook {ShouldPool : true }
46+ hook1 := & TestHook {ShouldPool : true , ShouldAccept : true }
47+ hook2 := & TestHook {ShouldPool : true , ShouldAccept : true }
4748
4849 manager .AddHook (hook1 )
4950 manager .AddHook (hook2 )
@@ -107,11 +108,12 @@ func TestHookErrorHandling(t *testing.T) {
107108
108109 // Hook that returns error on Get
109110 errorHook := & TestHook {
110- GetError : errors .New ("test error" ),
111- ShouldPool : true ,
111+ GetError : errors .New ("test error" ),
112+ ShouldPool : true ,
113+ ShouldAccept : true ,
112114 }
113115
114- normalHook := & TestHook {ShouldPool : true }
116+ normalHook := & TestHook {ShouldPool : true , ShouldAccept : true }
115117
116118 manager .AddHook (errorHook )
117119 manager .AddHook (normalHook )
@@ -145,9 +147,10 @@ func TestHookShouldRemove(t *testing.T) {
145147 removeHook := & TestHook {
146148 ShouldPool : false ,
147149 ShouldRemove : true ,
150+ ShouldAccept : true ,
148151 }
149152
150- normalHook := & TestHook {ShouldPool : true }
153+ normalHook := & TestHook {ShouldPool : true , ShouldAccept : true }
151154
152155 manager .AddHook (removeHook )
153156 manager .AddHook (normalHook )
@@ -181,7 +184,7 @@ func TestHookShouldRemove(t *testing.T) {
181184func TestPoolWithHooks (t * testing.T ) {
182185 // Create a pool with hooks
183186 hookManager := NewPoolHookManager ()
184- testHook := & TestHook {ShouldPool : true }
187+ testHook := & TestHook {ShouldPool : true , ShouldAccept : true }
185188 hookManager .AddHook (testHook )
186189
187190 opt := & Options {
@@ -208,7 +211,7 @@ func TestPoolWithHooks(t *testing.T) {
208211 }
209212
210213 // Test adding hook to pool
211- additionalHook := & TestHook {ShouldPool : true }
214+ additionalHook := & TestHook {ShouldPool : true , ShouldAccept : true }
212215 pool .AddPoolHook (additionalHook )
213216
214217 if pool .hookManager .GetHookCount () != 2 {
0 commit comments