@@ -10,11 +10,11 @@ import (
1010
1111// TestHook for testing hook functionality
1212type TestHook struct {
13- OnGetCalled int
14- OnPutCalled int
15- GetError error
16- PutError error
17- ShouldPool bool
13+ OnGetCalled int
14+ OnPutCalled int
15+ GetError error
16+ PutError error
17+ ShouldPool bool
1818 ShouldRemove bool
1919}
2020
@@ -30,97 +30,97 @@ func (th *TestHook) OnPut(ctx context.Context, conn *Conn) (shouldPool bool, sho
3030
3131func TestPoolHookManager (t * testing.T ) {
3232 manager := NewPoolHookManager ()
33-
33+
3434 // Test initial state
3535 if manager .GetHookCount () != 0 {
3636 t .Errorf ("Expected 0 hooks initially, got %d" , manager .GetHookCount ())
3737 }
38-
38+
3939 // Add hooks
4040 hook1 := & TestHook {ShouldPool : true }
4141 hook2 := & TestHook {ShouldPool : true }
42-
42+
4343 manager .AddHook (hook1 )
4444 manager .AddHook (hook2 )
45-
45+
4646 if manager .GetHookCount () != 2 {
4747 t .Errorf ("Expected 2 hooks after adding, got %d" , manager .GetHookCount ())
4848 }
49-
49+
5050 // Test ProcessOnGet
5151 ctx := context .Background ()
5252 conn := & Conn {} // Mock connection
53-
53+
5454 err := manager .ProcessOnGet (ctx , conn , false )
5555 if err != nil {
5656 t .Errorf ("ProcessOnGet should not error: %v" , err )
5757 }
58-
58+
5959 if hook1 .OnGetCalled != 1 {
6060 t .Errorf ("Expected hook1.OnGetCalled to be 1, got %d" , hook1 .OnGetCalled )
6161 }
62-
62+
6363 if hook2 .OnGetCalled != 1 {
6464 t .Errorf ("Expected hook2.OnGetCalled to be 1, got %d" , hook2 .OnGetCalled )
6565 }
66-
66+
6767 // Test ProcessOnPut
6868 shouldPool , shouldRemove , err := manager .ProcessOnPut (ctx , conn )
6969 if err != nil {
7070 t .Errorf ("ProcessOnPut should not error: %v" , err )
7171 }
72-
72+
7373 if ! shouldPool {
7474 t .Error ("Expected shouldPool to be true" )
7575 }
76-
76+
7777 if shouldRemove {
7878 t .Error ("Expected shouldRemove to be false" )
7979 }
80-
80+
8181 if hook1 .OnPutCalled != 1 {
8282 t .Errorf ("Expected hook1.OnPutCalled to be 1, got %d" , hook1 .OnPutCalled )
8383 }
84-
84+
8585 if hook2 .OnPutCalled != 1 {
8686 t .Errorf ("Expected hook2.OnPutCalled to be 1, got %d" , hook2 .OnPutCalled )
8787 }
88-
88+
8989 // Remove a hook
9090 manager .RemoveHook (hook1 )
91-
91+
9292 if manager .GetHookCount () != 1 {
9393 t .Errorf ("Expected 1 hook after removing, got %d" , manager .GetHookCount ())
9494 }
9595}
9696
9797func TestHookErrorHandling (t * testing.T ) {
9898 manager := NewPoolHookManager ()
99-
99+
100100 // Hook that returns error on Get
101101 errorHook := & TestHook {
102- GetError : errors .New ("test error" ),
102+ GetError : errors .New ("test error" ),
103103 ShouldPool : true ,
104104 }
105-
105+
106106 normalHook := & TestHook {ShouldPool : true }
107-
107+
108108 manager .AddHook (errorHook )
109109 manager .AddHook (normalHook )
110-
110+
111111 ctx := context .Background ()
112112 conn := & Conn {}
113-
113+
114114 // Test that error stops processing
115115 err := manager .ProcessOnGet (ctx , conn , false )
116116 if err == nil {
117117 t .Error ("Expected error from ProcessOnGet" )
118118 }
119-
119+
120120 if errorHook .OnGetCalled != 1 {
121121 t .Errorf ("Expected errorHook.OnGetCalled to be 1, got %d" , errorHook .OnGetCalled )
122122 }
123-
123+
124124 // normalHook should not be called due to error
125125 if normalHook .OnGetCalled != 0 {
126126 t .Errorf ("Expected normalHook.OnGetCalled to be 0, got %d" , normalHook .OnGetCalled )
@@ -129,46 +129,44 @@ func TestHookErrorHandling(t *testing.T) {
129129
130130func TestHookShouldRemove (t * testing.T ) {
131131 manager := NewPoolHookManager ()
132-
132+
133133 // Hook that says to remove connection
134134 removeHook := & TestHook {
135- ShouldPool : false ,
135+ ShouldPool : false ,
136136 ShouldRemove : true ,
137137 }
138-
138+
139139 normalHook := & TestHook {ShouldPool : true }
140-
140+
141141 manager .AddHook (removeHook )
142142 manager .AddHook (normalHook )
143-
143+
144144 ctx := context .Background ()
145145 conn := & Conn {}
146-
146+
147147 shouldPool , shouldRemove , err := manager .ProcessOnPut (ctx , conn )
148148 if err != nil {
149149 t .Errorf ("ProcessOnPut should not error: %v" , err )
150150 }
151-
151+
152152 if shouldPool {
153153 t .Error ("Expected shouldPool to be false" )
154154 }
155-
155+
156156 if ! shouldRemove {
157157 t .Error ("Expected shouldRemove to be true" )
158158 }
159-
159+
160160 if removeHook .OnPutCalled != 1 {
161161 t .Errorf ("Expected removeHook.OnPutCalled to be 1, got %d" , removeHook .OnPutCalled )
162162 }
163-
163+
164164 // normalHook should not be called due to early return
165165 if normalHook .OnPutCalled != 0 {
166166 t .Errorf ("Expected normalHook.OnPutCalled to be 0, got %d" , normalHook .OnPutCalled )
167167 }
168168}
169169
170-
171-
172170func TestPoolWithHooks (t * testing.T ) {
173171 // Create a pool with hooks
174172 hookManager := NewPoolHookManager ()
0 commit comments