(t *testing.T)
| 35 | } |
| 36 | |
| 37 | func 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 { |
nothing calls this directly
no test coverage detected