package oci import "testing" func TestAllRegionsParsesAndComplete(t *testing.T) { regions, err := AllRegions() if err != nil { t.Fatalf("AllRegions: %v", err) } if len(regions) == 0 { t.Fatal("AllRegions returned empty table") } seen := make(map[string]bool, len(regions)) for _, r := range regions { if r.Alias == "" || r.Key == "" || r.Name == "" { t.Errorf("region %+v has empty field", r) } if seen[r.Key] { t.Errorf("duplicate region key %s", r.Key) } seen[r.Key] = true } } func TestRegionByKey(t *testing.T) { tests := []struct { name string key string wantName string wantFound bool }{ {name: "精确命中", key: "FRA", wantName: "eu-frankfurt-1", wantFound: true}, {name: "小写命中", key: "fra", wantName: "eu-frankfurt-1", wantFound: true}, {name: "不存在", key: "XXX", wantFound: false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { info, found := RegionByKey(tt.key) if found != tt.wantFound { t.Fatalf("RegionByKey(%q) found = %v, want %v", tt.key, found, tt.wantFound) } if found && info.Name != tt.wantName { t.Errorf("RegionByKey(%q).Name = %q, want %q", tt.key, info.Name, tt.wantName) } }) } }