fix(delivery): add PostgreSQL rollback and CloudDM isolation
This commit is contained in:
@@ -2,7 +2,10 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/1024XEngineer/xinfra/server/internal/model"
|
||||
)
|
||||
|
||||
func TestValidatePostgreSQLDeliveryInput(t *testing.T) {
|
||||
@@ -102,3 +105,42 @@ func TestSelectPostgreSQLHosts(t *testing.T) {
|
||||
t.Fatal("host outside the pool was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildPostgreSQLCloudDMRegisterRequest(t *testing.T) {
|
||||
req := buildPostgreSQLCloudDMRegisterRequest(
|
||||
model.PostgreSQLInstance{ID: 42, InstanceID: "orders-pg-primary", HostIP: "10.0.0.10", Port: 15432, VersionMajor: "16", Role: "primary"},
|
||||
model.PostgreSQLCluster{ID: 7, Name: "orders-pg"},
|
||||
"postgres",
|
||||
"secret",
|
||||
)
|
||||
if req.SourceSystem != "xinfra" || req.ResourceType != "POSTGRESQL_INSTANCE" {
|
||||
t.Fatalf("unexpected request metadata: %#v", req)
|
||||
}
|
||||
if req.ExternalResourceID != "postgresql-instance:42" {
|
||||
t.Fatalf("unexpected externalResourceId: %q", req.ExternalResourceID)
|
||||
}
|
||||
if req.DataSource.DSType != "PostgreSQL" || req.DataSource.Host != "10.0.0.10:15432" || req.DataSource.UserName != "postgres" || req.DataSource.Password != "secret" {
|
||||
t.Fatalf("unexpected PostgreSQL data source: %#v", req.DataSource)
|
||||
}
|
||||
if req.DataSource.PostgreSQLVersion != "16" || req.DataSource.DefaultSchema != "postgres" {
|
||||
t.Fatalf("unexpected PostgreSQL version/schema: %#v", req.DataSource)
|
||||
}
|
||||
raw, err := json.Marshal(req)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal PostgreSQL CloudDM request: %v", err)
|
||||
}
|
||||
var decoded map[string]any
|
||||
if err := json.Unmarshal(raw, &decoded); err != nil {
|
||||
t.Fatalf("decode PostgreSQL CloudDM request: %v", err)
|
||||
}
|
||||
dataSource := decoded["dataSource"].(map[string]any)
|
||||
if dataSource["postgresql_version"] != "16" {
|
||||
t.Fatalf("postgresql_version missing from contract: %#v", dataSource)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostgreSQLCloudDMExternalResourceID(t *testing.T) {
|
||||
if got := postgresqlCloudDMExternalResourceID(99); got != "postgresql-instance:99" {
|
||||
t.Fatalf("external resource id = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user