package service import "testing" func TestValidateDeliveryInput(t *testing.T) { 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) } withVersion := valid withVersion.MySQLVersion = "8.0" if err := validateDeliveryInput(withVersion); err != nil { t.Fatalf("valid input with version 8.0 rejected: %v", err) } for name, input := range map[string]MySQLDeliveryInput{ "uppercase namespace": valid, "bad instance": 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 "bad cpu cores": input.CPUCores = 3 case "too much memory": input.MemoryGB = 128 case "too little storage": input.StorageGB = 10 case "too much storage": 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) } } }