feat: enhance host resolution, filtering, and cache management
Release / release (push) Successful in 49s
Release / release (push) Successful in 49s
- **Strategies**: Add resolver strategy input validation and parsing in setup wizard. Support comma-separated input with known strategy mapping. - **Client**: Extend Search and SearchAll to include kind and tag filters. Add pagination for full cache refresh handling large datasets. - **Cache**: Introduce `RecentlyUsed` and `MarkUsed`. Persist `LastUsed` timestamps for entries. - **TUI**: Add recent hosts view, tag/kind filters, and inline editor for user/port override. - **Tests**: Comprehensive unit tests for new features, including strategy validation, cache behavior, and client filtering. - **Docs**: Update README with new TUI features and cache subcommands.
This commit is contained in:
@@ -116,6 +116,68 @@ func TestSave_CreatesConfigDir(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseStrategies(t *testing.T) {
|
||||
tests := []struct {
|
||||
in string
|
||||
want []string
|
||||
}{
|
||||
{"primary_ip", []string{"primary_ip"}},
|
||||
{"management_subnet, primary_ip", []string{"management_subnet", "primary_ip"}},
|
||||
{"primary_ip,management_subnet,interface_name", []string{"primary_ip", "management_subnet", "interface_name"}},
|
||||
{" primary_ip , management_subnet ", []string{"primary_ip", "management_subnet"}},
|
||||
{"", nil},
|
||||
{" , ", nil},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
got := parseStrategies(tt.in)
|
||||
if len(got) != len(tt.want) {
|
||||
t.Errorf("parseStrategies(%q): got %v, want %v", tt.in, got, tt.want)
|
||||
continue
|
||||
}
|
||||
for i := range got {
|
||||
if got[i] != tt.want[i] {
|
||||
t.Errorf("parseStrategies(%q)[%d]: got %q, want %q", tt.in, i, got[i], tt.want[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseStrategies_PreservesOrder(t *testing.T) {
|
||||
got := parseStrategies("interface_name, management_subnet, primary_ip")
|
||||
want := []string{"interface_name", "management_subnet", "primary_ip"}
|
||||
for i, s := range got {
|
||||
if s != want[i] {
|
||||
t.Errorf("order not preserved at [%d]: got %q, want %q", i, s, want[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateStrategies_Valid(t *testing.T) {
|
||||
cases := []string{
|
||||
"primary_ip",
|
||||
"management_subnet, primary_ip",
|
||||
"interface_name, management_subnet, primary_ip",
|
||||
}
|
||||
for _, c := range cases {
|
||||
if err := validateStrategies(c); err != nil {
|
||||
t.Errorf("validateStrategies(%q) should be valid, got: %v", c, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateStrategies_Invalid(t *testing.T) {
|
||||
cases := []string{
|
||||
"",
|
||||
"unknown_strategy",
|
||||
"primary_ip, typo",
|
||||
}
|
||||
for _, c := range cases {
|
||||
if err := validateStrategies(c); err == nil {
|
||||
t.Errorf("validateStrategies(%q) should return an error", c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSave_RoundtripViaLoad(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
orig := os.Getenv("XDG_CONFIG_HOME")
|
||||
|
||||
Reference in New Issue
Block a user