feat: register MySQL instances in CloudDM
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -131,6 +132,38 @@ 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},
|
||||
deliveryPayload{MySQLDeliveryInput: MySQLDeliveryInput{InstanceDesc: "支付生产 MySQL", Timezone: "Asia/Shanghai"}},
|
||||
"secret",
|
||||
)
|
||||
if req.SourceSystem != "xinfra" || req.ResourceType != "MYSQL_INSTANCE" {
|
||||
t.Fatalf("unexpected request metadata: %#v", req)
|
||||
}
|
||||
if req.ExternalResourceID != "mysql-instance:42" {
|
||||
t.Fatalf("unexpected externalResourceId: %q", req.ExternalResourceID)
|
||||
}
|
||||
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.ClientTimeZone != "Asia/Shanghai" || req.DataSource.ConnectionCharset != "utf8" {
|
||||
t.Fatalf("unexpected time zone or charset: %#v", req.DataSource)
|
||||
}
|
||||
raw, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal CloudDM request: %v", err)
|
||||
}
|
||||
var decoded map[string]any
|
||||
if err := json.Unmarshal(raw, &decoded); err != nil {
|
||||
t.Fatalf("unmarshal CloudDM request: %v", err)
|
||||
}
|
||||
dataSource := decoded["dataSource"].(map[string]any)
|
||||
if value, ok := dataSource["defaultSchema"]; !ok || value != nil {
|
||||
t.Fatalf("defaultSchema must be present as null, got %#v", dataSource["defaultSchema"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestRollbackExtraVarsTargetsOnlyTheAllocatedInstance(t *testing.T) {
|
||||
task := &model.DeliveryTask{ID: "task-1", TargetHost: "db-01"}
|
||||
payload := deliveryPayload{MySQLDeliveryInput: MySQLDeliveryInput{InstanceName: "mysql-a", DataDisk: "/disk1"}}
|
||||
|
||||
Reference in New Issue
Block a user