mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-10-20 10:52:08 +00:00
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package unifiedresources
|
|
|
|
import "testing"
|
|
|
|
func TestSourceSpecificIDMatchesRegistryIngest(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
rr := NewRegistry(nil)
|
|
|
|
sourceID := "lab:pve-a:100"
|
|
|
|
vm := Resource{
|
|
Type: ResourceTypeVM,
|
|
Name: "vm-100",
|
|
Status: StatusOnline,
|
|
}
|
|
|
|
rr.IngestRecords(SourceProxmox, []IngestRecord{
|
|
{SourceID: sourceID, Resource: vm},
|
|
})
|
|
|
|
resources := rr.ListByType(ResourceTypeVM)
|
|
if len(resources) != 1 {
|
|
t.Fatalf("expected 1 VM resource, got %d", len(resources))
|
|
}
|
|
|
|
got := resources[0].ID
|
|
want := SourceSpecificID(ResourceTypeVM, SourceProxmox, sourceID)
|
|
if got != want {
|
|
t.Fatalf("resource ID mismatch: got %q want %q", got, want)
|
|
}
|
|
}
|
|
|
|
func TestSourceSpecificIDCanonicalizesSourceIDWhitespace(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
got := SourceSpecificID(ResourceTypeVM, SourceProxmox, " lab:pve-a:100 ")
|
|
want := SourceSpecificID(ResourceTypeVM, SourceProxmox, "lab:pve-a:100")
|
|
if got != want {
|
|
t.Fatalf("SourceSpecificID should trim source ID whitespace: got %q want %q", got, want)
|
|
}
|
|
}
|