Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Refactor compatibility test cases

天舟a75333c77182
diff --git a/plugin/advisor/mysql/mysql_migration_compatibility_advisor_test.go b/plugin/advisor/mysql/mysql_migration_compatibility_advisor_test.go
index 73f15aef87..f8a8a8d22b 100644
--- a/plugin/advisor/mysql/mysql_migration_compatibility_advisor_test.go
+++ b/plugin/advisor/mysql/mysql_migration_compatibility_advisor_test.go
@@ -8,12 +8,32 @@ import (
"go.uber.org/zap"
)
-func TestBasic(t *testing.T) {
- type test struct {
- statement string
- want []advisor.Advice
+type test struct {
+ statement string
+ want []advisor.Advice
+}
+
+func runTests(t *testing.T, tests []test) {
+ adv := CompatibilityAdvisor{}
+ logger, _ := zap.NewDevelopmentConfig().Build()
+ ctx := advisor.AdvisorContext{
+ Logger: logger,
+ Charset: "",
+ Collation: "",
}
+ for _, tc := range tests {
+ adviceList, err := adv.Check(ctx, tc.statement)
+ if err != nil {
+ t.Errorf("statement=%s: expected no error, got %v", tc.statement, err)
+ } else {
+ if !reflect.DeepEqual(tc.want, adviceList) {
+ t.Errorf("statement=%s: expected %+v, got %+v", tc.statement, tc.want, adviceList)
+ }
+ }
+ }
+}
+func TestBasic(t *testing.T) {
tests := []test{
{
statement: "DROP DATABASE d1",
@@ -82,31 +102,10 @@ func TestBasic(t *testing.T) {
},
}
- adv := CompatibilityAdvisor{}
- logger, _ := zap.NewDevelopmentConfig().Build()
- ctx := advisor.AdvisorContext{
- Logger: logger,
- Charset: "",
- Collation: "",
- }
- for _, tc := range tests {
- adviceList, err := adv.Check(ctx, tc.statement)
- if err != nil {
- t.Errorf("statement=%s: expected no error, got %v", tc.statement, err)
- } else {
- if !reflect.DeepEqual(tc.want, adviceList) {
- t.Errorf("statement=%s: expected %+v, got %+v", tc.statement, tc.want, adviceList)
- }
- }
- }
+ runTests(t, tests)
}
func TestAlterTable(t *testing.T) {
- type test struct {
- statement string
- want []advisor.Advice
- }
-
tests := []test{
{
statement: "ALTER TABLE t1 ADD f1 TEXT",
@@ -250,21 +249,5 @@ func TestAlterTable(t *testing.T) {
},
}
- adv := CompatibilityAdvisor{}
- logger, _ := zap.NewDevelopmentConfig().Build()
- ctx := advisor.AdvisorContext{
- Logger: logger,
- Charset: "",
- Collation: "",
- }
- for _, tc := range tests {
- adviceList, err := adv.Check(ctx, tc.statement)
- if err != nil {
- t.Errorf("statement=%s: expected no error, got %v", tc.statement, err)
- } else {
- if !reflect.DeepEqual(tc.want, adviceList) {
- t.Errorf("statement=%s: expected %+v, got %+v", tc.statement, tc.want, adviceList)
- }
- }
- }
+ runTests(t, tests)
}