feat(delivery): switch AWX delivery to callbacks

This commit is contained in:
mac
2026-07-27 15:19:18 +08:00
parent 97f0de16bc
commit e0ee36cadb
9 changed files with 594 additions and 104 deletions
+24 -7
View File
@@ -3,7 +3,8 @@ package service
import "testing"
func TestValidateDeliveryInput(t *testing.T) {
valid := MySQLDeliveryInput{BusinessLineID: 1, TargetID: 1, Namespace: "team-a", InstanceName: "mysql-01", CPUMilli: 500, MemoryMi: 1024, StorageGi: 10}
valid := MySQLDeliveryInput{BusinessLineID: 1, TargetID: 1, Namespace: "team-a", InstanceName: "mysql-01", CPUCores: 2, MemoryGB: 4, StorageGB: 50}
normalizeMySQLDeliveryInput(&valid)
if err := validateDeliveryInput(valid); err != nil {
t.Fatalf("valid input rejected: %v", err)
}
@@ -15,27 +16,43 @@ func TestValidateDeliveryInput(t *testing.T) {
for name, input := range map[string]MySQLDeliveryInput{
"uppercase namespace": valid,
"bad instance": valid,
"too little memory": valid,
"bad cpu cores": valid,
"too much memory": valid,
"too little storage": valid,
"too much storage": valid,
"unsupported version": valid,
"unsupported topology": valid,
"bad mysql port": valid,
"bad data disk": valid,
"unsupported charset": valid,
"bad collation": valid,
} {
switch name {
case "uppercase namespace":
input.Namespace = "Team-A"
case "bad instance":
input.InstanceName = "mysql_01"
case "too little memory":
input.MemoryMi = 512
case "bad cpu cores":
input.CPUCores = 3
case "too much memory":
input.MemoryMi = 8192
input.MemoryGB = 128
case "too little storage":
input.StorageGi = 5
input.StorageGB = 10
case "too much storage":
input.StorageGi = 200
input.StorageGB = 3000
case "unsupported version":
input.MySQLVersion = "5.7"
case "unsupported topology":
input.Topology = "mgr"
case "bad mysql port":
input.MySQLPort = 3306
case "bad data disk":
input.DataDisk = "/"
case "unsupported charset":
input.CharacterSet = "sjis"
case "bad collation":
input.CharacterSet = "utf8"
input.Collation = "utf8mb4_general_ci"
}
if err := validateDeliveryInput(input); err == nil {
t.Errorf("%s was accepted", name)