mirror of
https://github.com/turbot/steampipe.git
synced 2025-12-19 18:12:43 -05:00
This commit is contained in:
@@ -647,6 +647,9 @@ func (c *InteractiveClient) getTableAndConnectionSuggestions(word string) []prom
|
||||
|
||||
connection := strings.TrimSpace(parts[0])
|
||||
t := c.suggestions.tablesBySchema[connection]
|
||||
if t == nil {
|
||||
return []prompt.Suggest{}
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
|
||||
70
pkg/interactive/interactive_client_test.go
Normal file
70
pkg/interactive/interactive_client_test.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package interactive
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/c-bata/go-prompt"
|
||||
)
|
||||
|
||||
// TestGetTableAndConnectionSuggestions_ReturnsEmptySliceNotNil tests that
|
||||
// getTableAndConnectionSuggestions returns an empty slice instead of nil
|
||||
// when no matching connection is found in the schema.
|
||||
//
|
||||
// This is important for proper API contract - functions that return slices
|
||||
// should return empty slices rather than nil to avoid unexpected nil pointer
|
||||
// issues in calling code.
|
||||
//
|
||||
// Bug: #4710
|
||||
// PR: #4734
|
||||
func TestGetTableAndConnectionSuggestions_ReturnsEmptySliceNotNil(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
word string
|
||||
expected bool // true if we expect non-nil result
|
||||
}{
|
||||
{
|
||||
name: "empty word should return non-nil",
|
||||
word: "",
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "unqualified table should return non-nil",
|
||||
word: "table",
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "non-existent connection should return non-nil",
|
||||
word: "nonexistent.table",
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "qualified table with dot should return non-nil",
|
||||
word: "aws.instances",
|
||||
expected: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Create a minimal InteractiveClient with empty suggestions
|
||||
c := &InteractiveClient{
|
||||
suggestions: &autoCompleteSuggestions{
|
||||
schemas: []prompt.Suggest{},
|
||||
unqualifiedTables: []prompt.Suggest{},
|
||||
tablesBySchema: make(map[string][]prompt.Suggest),
|
||||
},
|
||||
}
|
||||
|
||||
result := c.getTableAndConnectionSuggestions(tt.word)
|
||||
|
||||
if tt.expected && result == nil {
|
||||
t.Errorf("getTableAndConnectionSuggestions(%q) returned nil, expected non-nil empty slice", tt.word)
|
||||
}
|
||||
|
||||
// Additional check: even if not nil, should be empty in these test cases
|
||||
if result != nil && len(result) != 0 {
|
||||
t.Errorf("getTableAndConnectionSuggestions(%q) returned non-empty slice %v, expected empty slice", tt.word, result)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user