package kvm import "testing" func TestParseProviderID_roundTrip(t *testing.T) { t.Parallel() id := formatProviderID("nas1", "proxy-abc123def456ghij") if id != "hosts/nas1/domains/proxy-abc123def456ghij" { t.Fatalf("formatProviderID() = %q", id) } host, name, err := parseProviderID(id) if err != nil { t.Fatalf("parseProviderID(%q) error = %v", id, err) } if host != "nas1" || name != "proxy-abc123def456ghij" { t.Errorf("parseProviderID(%q) = %q, %q", id, host, name) } } func TestParseProviderID_malformed(t *testing.T) { t.Parallel() tests := []struct { name string id string }{ {"empty", ""}, {"gcp style", "zones/europe-west1-b/instances/proxy-x"}, {"missing name", "hosts/nas1/domains/"}, {"missing host", "hosts//domains/proxy-x"}, {"too many segments", "hosts/nas1/domains/proxy-x/extra"}, {"bare name", "proxy-x"}, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { t.Parallel() if _, _, err := parseProviderID(tc.id); err == nil { t.Errorf("parseProviderID(%q) error = nil, want error", tc.id) } }) } }