test(xinfra): cover clouddm register metadata

This commit is contained in:
2026-07-30 17:07:06 +08:00
parent 57ba098fe3
commit a72567a84a
+13 -1
View File
@@ -147,7 +147,7 @@ func TestAllocatePort(t *testing.T) {
func TestBuildCloudDMRegisterRequest(t *testing.T) {
req := buildCloudDMRegisterRequest(
model.DeploymentResult{ID: 42, InstanceName: "mysql-payment-prod", Host: "10.0.0.10", Port: 3306},
model.DeploymentResult{ID: 42, InstanceName: "mysql-payment-prod", Host: "10.0.0.10", Port: 3306, Version: "8.4"},
deliveryPayload{MySQLDeliveryInput: MySQLDeliveryInput{InstanceDesc: "支付生产 MySQL", Timezone: "Asia/Shanghai"}},
"secret",
)
@@ -160,6 +160,12 @@ func TestBuildCloudDMRegisterRequest(t *testing.T) {
if req.DataSource.Host != "10.0.0.10:3306" || req.DataSource.Password != "secret" {
t.Fatalf("unexpected data source fields: %#v", req.DataSource)
}
if req.DataSource.ClusterID != nil {
t.Fatalf("cluster_id must be nullable when xinfra cannot resolve it, got %#v", req.DataSource.ClusterID)
}
if req.DataSource.MySQLVersion != "8.4" {
t.Fatalf("unexpected mysql version: %#v", req.DataSource.MySQLVersion)
}
if req.DataSource.ClientTimeZone != "Asia/Shanghai" || req.DataSource.ConnectionCharset != "utf8" {
t.Fatalf("unexpected time zone or charset: %#v", req.DataSource)
}
@@ -175,6 +181,12 @@ func TestBuildCloudDMRegisterRequest(t *testing.T) {
if value, ok := dataSource["defaultSchema"]; !ok || value != nil {
t.Fatalf("defaultSchema must be present as null, got %#v", dataSource["defaultSchema"])
}
if value, ok := dataSource["cluster_id"]; !ok || value != nil {
t.Fatalf("cluster_id must be present as null, got %#v", dataSource["cluster_id"])
}
if value, ok := dataSource["mysql_version"]; !ok || value != "8.4" {
t.Fatalf("mysql_version must be propagated from deployed instance, got %#v", value)
}
}
func TestCloudDMDataSourceIDFromResponse(t *testing.T) {