feat: search multiple NetBox instances with isolated host identities
Release / release (push) Successful in 5m16s

This commit is contained in:
Sebastian Unterschütz committed 2026-10-27 23:14:42 +01:00
1 parent a2a6dd7591
commit 7f53b90266
26 files changed
+1299 -115

No files matched your search

+2 -1
View File
@@ -258,7 +258,8 @@ func (c *Cache) Search(prefix string) []Entry {
prefix = strings.ToLower(prefix)
var out []Entry
for name, e := range c.entries {
if strings.HasPrefix(strings.ToLower(name), prefix) {
_, hostname, qualified := strings.Cut(strings.ToLower(name), "/")
if strings.HasPrefix(strings.ToLower(name), prefix) || (qualified && !strings.Contains(prefix, "/") && strings.HasPrefix(hostname, prefix)) {
out = append(out, e)
}
}
+12
View File
@@ -483,3 +483,15 @@ func TestUpsertPreservesUsageHistory(t *testing.T) {
t.Fatalf("history lost: %+v", after)
}
}
func TestSearchMatchesHostnamesAcrossQualifiedSources(t *testing.T) {
c := New("", 3600)
c.Upsert(Entry{Name: "office/web01", IP: "10.0.0.1"})
c.Upsert(Entry{Name: "lab/web01", IP: "10.0.0.2"})
c.Upsert(Entry{Name: "lab/db01", IP: "10.0.0.3"})
for query, want := range map[string]int{"web": 2, "office/web": 1, "lab/": 2, "WEB": 2} {
if got := len(c.Search(query)); got != want {
t.Errorf("Search(%q)=%d, want %d", query, got, want)
}
}
}