Introduces internal/provider/kvm with the side-effect-free pieces of the provider: providerID format/parse, the namespaced <metadata> element that carries the GC contract, q35 domain XML over pool volumes, volume XML for overlays and raw seeds, the NoCloud seed ISO built with kdomanski/iso9660, and config defaults. All unit-tested. Step 2 of docs/plans/2026-09-04-1404-kvm-provider.md. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
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)
|
|
}
|
|
})
|
|
}
|
|
}
|