mirror of
https://github.com/turbot/steampipe.git
synced 2025-12-19 18:12:43 -05:00
* Add test for #4713: initialiseSchemaAndTableSuggestions should handle nil client * Fix #4713: Add nil check in initialiseSchemaAndTableSuggestions
This commit is contained in:
@@ -44,6 +44,11 @@ func (c *InteractiveClient) initialiseSchemaAndTableSuggestions(connectionStateM
|
||||
return
|
||||
}
|
||||
|
||||
// check if client is nil to avoid panic
|
||||
if c.client() == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// unqualified table names
|
||||
// use lookup to avoid dupes from dynamic plugins
|
||||
// (this is needed as GetFirstSearchPathConnectionForPlugins will return ALL dynamic connections)
|
||||
|
||||
33
pkg/interactive/interactive_client_autocomplete_test.go
Normal file
33
pkg/interactive/interactive_client_autocomplete_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package interactive
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/turbot/steampipe/v2/pkg/db/db_common"
|
||||
"github.com/turbot/steampipe/v2/pkg/steampipeconfig"
|
||||
)
|
||||
|
||||
// TestInitialiseSchemaAndTableSuggestions_NilClient tests that initialiseSchemaAndTableSuggestions
|
||||
// handles a nil client gracefully without panicking.
|
||||
// This is a regression test for bug #4713.
|
||||
func TestInitialiseSchemaAndTableSuggestions_NilClient(t *testing.T) {
|
||||
// Create an InteractiveClient with nil initData, which causes client() to return nil
|
||||
c := &InteractiveClient{
|
||||
initData: nil, // This will cause client() to return nil
|
||||
suggestions: newAutocompleteSuggestions(),
|
||||
// Set schemaMetadata to non-nil so we get past the early return on line 43
|
||||
schemaMetadata: &db_common.SchemaMetadata{
|
||||
Schemas: make(map[string]map[string]db_common.TableSchema),
|
||||
TemporarySchemaName: "temp",
|
||||
},
|
||||
}
|
||||
|
||||
// Create an empty connection state map
|
||||
connectionStateMap := steampipeconfig.ConnectionStateMap{}
|
||||
|
||||
// This should not panic - the function should handle nil client gracefully
|
||||
assert.NotPanics(t, func() {
|
||||
c.initialiseSchemaAndTableSuggestions(connectionStateMap)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user