feat: search multiple NetBox instances with isolated host identities
Release / release (push) Successful in 5m16s
Release / release (push) Successful in 5m16s
This commit is contained in:
1 parent
a2a6dd7591
commit
7f53b90266
26 files changed
+1299
-115
No files matched your search
@@ -50,3 +50,35 @@ func TestUnreadableNoteIsNotTreatedAsEmpty(t *testing.T) {
|
||||
t.Fatal("expected read error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLocalNotesSeparateInstancesAndSurviveRename(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
client := netbox.NewMultiClient([]netbox.Source{{Name: "office", URL: "https://office.example"}, {Name: "lab", URL: "https://lab.example"}})
|
||||
service := &Service{Dir: t.TempDir(), Client: client}
|
||||
for _, source := range []string{"office", "lab"} {
|
||||
note := Note{Host: netbox.HostEntry{Name: source + "/web", Kind: "device"}, Text: source + " private note"}
|
||||
if err := service.Write(ctx, note, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for _, source := range []string{"office", "lab"} {
|
||||
note, err := service.Read(ctx, netbox.HostEntry{Name: source + "/web", Kind: "device"}, false)
|
||||
if err != nil || note.Text != source+" private note" {
|
||||
t.Fatalf("notes crossed instances: %+v, %v", note, err)
|
||||
}
|
||||
}
|
||||
service.Client = netbox.NewMultiClient([]netbox.Source{{Name: "renamed", URL: "https://office.example"}})
|
||||
note, err := service.Read(ctx, netbox.HostEntry{Name: "renamed/web", Kind: "device"}, false)
|
||||
if err != nil || note.Text != "office private note" {
|
||||
t.Fatalf("renaming source lost note: %+v, %v", note, err)
|
||||
}
|
||||
// This is also the namespace used before migrating a legacy single NetBox.
|
||||
legacy := &Service{Dir: service.Dir, Namespace: "https://office.example"}
|
||||
note, err = legacy.Read(ctx, netbox.HostEntry{Name: "web", Kind: "device"}, false)
|
||||
if err != nil || note.Text != "office private note" {
|
||||
t.Fatalf("legacy note namespace changed: %+v, %v", note, err)
|
||||
}
|
||||
if err := service.Write(ctx, Note{Host: netbox.HostEntry{Name: "web", Kind: "device"}}, false); err == nil {
|
||||
t.Fatal("unqualified notes accepted for multiple sources")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user