mirror of
https://github.com/turbot/steampipe.git
synced 2025-12-19 18:12:43 -05:00
* Add test for #4698: ResetPools should handle nil pools gracefully * Fix #4698: Add nil checks to ResetPools method
This commit is contained in:
@@ -246,8 +246,12 @@ func (c *DbClient) ResetPools(ctx context.Context) {
|
||||
log.Println("[TRACE] db_client.ResetPools start")
|
||||
defer log.Println("[TRACE] db_client.ResetPools end")
|
||||
|
||||
c.userPool.Reset()
|
||||
c.managementPool.Reset()
|
||||
if c.userPool != nil {
|
||||
c.userPool.Reset()
|
||||
}
|
||||
if c.managementPool != nil {
|
||||
c.managementPool.Reset()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *DbClient) buildSchemasQuery(schemas ...string) string {
|
||||
|
||||
@@ -288,6 +288,27 @@ func TestDbClient_ClosePools_NilPoolsHandling(t *testing.T) {
|
||||
}, "closePools should handle nil pools gracefully")
|
||||
}
|
||||
|
||||
// TestResetPools verifies that ResetPools handles nil pools gracefully without panicking.
|
||||
// This test addresses bug #4698 where ResetPools panics when called on a DbClient with nil pools.
|
||||
func TestResetPools(t *testing.T) {
|
||||
// Create a DbClient with nil pools (simulating a partially initialized or closed client)
|
||||
client := &DbClient{
|
||||
userPool: nil,
|
||||
managementPool: nil,
|
||||
}
|
||||
|
||||
// ResetPools should NOT panic even with nil pools
|
||||
// This is the expected correct behavior
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
t.Errorf("ResetPools panicked with nil pools: %v", r)
|
||||
}
|
||||
}()
|
||||
|
||||
ctx := context.Background()
|
||||
client.ResetPools(ctx)
|
||||
}
|
||||
|
||||
// TestDbClient_SessionsMapInitialized verifies sessions map is initialized in NewDbClient
|
||||
func TestDbClient_SessionsMapInitialized(t *testing.T) {
|
||||
// Verify the initialization happens in NewDbClient
|
||||
|
||||
Reference in New Issue
Block a user