初始提交:OCI 面板后端(含 GenAI 网关一期)

This commit is contained in:
Wang Defa
2026-07-09 15:31:04 +08:00
commit b9a3e97e84
168 changed files with 31794 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
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)
}
})
}
}