mirror of
https://github.com/turbot/steampipe.git
synced 2025-12-19 18:12:43 -05:00
* Unskip test demonstrating bug #4796: RunBatchSession panics with nil Client Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix #4796: Add nil check for Client in RunBatchSession Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -64,6 +64,11 @@ func RunBatchSession(ctx context.Context, initData *query.InitData) (int, error)
|
||||
// display any initialisation messages/warnings
|
||||
initData.Result.DisplayMessages()
|
||||
|
||||
// validate that Client is not nil
|
||||
if initData.Client == nil {
|
||||
return 0, fmt.Errorf("client is required but not initialized")
|
||||
}
|
||||
|
||||
// if there is a custom search path, wait until the first connection of each plugin has loaded
|
||||
if customSearchPath := initData.Client.GetCustomSearchPath(); customSearchPath != nil {
|
||||
if err := connection_sync.WaitForSearchPathSchemas(ctx, initData.Client, customSearchPath); err != nil {
|
||||
|
||||
@@ -84,6 +84,29 @@ func TestRunBatchSession_InitError(t *testing.T) {
|
||||
assert.Equal(t, 0, failures, "Should return 0 failures when init fails")
|
||||
}
|
||||
|
||||
// TestRunBatchSession_NilClient tests that RunBatchSession handles nil Client gracefully
|
||||
func TestRunBatchSession_NilClient(t *testing.T) {
|
||||
// Create initData with nil Client
|
||||
initData := &query.InitData{
|
||||
InitData: initialisation.InitData{
|
||||
Result: &db_common.InitResult{},
|
||||
Client: nil, // nil Client should be handled gracefully
|
||||
},
|
||||
Loaded: make(chan struct{}),
|
||||
}
|
||||
|
||||
// Signal that init is complete
|
||||
close(initData.Loaded)
|
||||
|
||||
// This should not panic - it should handle nil Client gracefully
|
||||
_, err := RunBatchSession(context.Background(), initData)
|
||||
|
||||
// We expect an error indicating that Client is required, not a panic
|
||||
if err == nil {
|
||||
t.Error("Expected error when Client is nil, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
// Test Suite: Helper Functions
|
||||
|
||||
func TestNeedSnapshot_DefaultValues(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user