|
| 1 | +package constant |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestCheckDBTypeIfDataExportSupported_NewTypes(t *testing.T) { |
| 8 | + // 验证新增的数据源应在白名单中 |
| 9 | + newTypes := map[string]bool{ |
| 10 | + "TiDB": true, |
| 11 | + "TDSQL For InnoDB": true, |
| 12 | + "GoldenDB": true, |
| 13 | + "TBase": true, |
| 14 | + "GaussDB for MySQL": true, // GaussDB/openGauss: ParseDBType 的输入值是 "GaussDB for MySQL" |
| 15 | + "DB2": true, |
| 16 | + } |
| 17 | + for dbType, expectedSupported := range newTypes { |
| 18 | + t.Run(dbType, func(t *testing.T) { |
| 19 | + got := CheckDBTypeIfDataExportSupported(dbType) |
| 20 | + if got != expectedSupported { |
| 21 | + t.Errorf("CheckDBTypeIfDataExportSupported(%q) = %v, want %v", dbType, got, expectedSupported) |
| 22 | + } |
| 23 | + }) |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +func TestCheckDBTypeIfDataExportSupported_ExistingTypes(t *testing.T) { |
| 28 | + // 回归测试: 验证已有的 7 种数据源仍在白名单中 |
| 29 | + existingTypes := map[string]bool{ |
| 30 | + "MySQL": true, |
| 31 | + "PostgreSQL": true, |
| 32 | + "Oracle": true, |
| 33 | + "SQL Server": true, |
| 34 | + "OceanBase For MySQL": true, |
| 35 | + "Hive": true, |
| 36 | + "DM": true, |
| 37 | + } |
| 38 | + for dbType, expectedSupported := range existingTypes { |
| 39 | + t.Run(dbType, func(t *testing.T) { |
| 40 | + got := CheckDBTypeIfDataExportSupported(dbType) |
| 41 | + if got != expectedSupported { |
| 42 | + t.Errorf("CheckDBTypeIfDataExportSupported(%q) = %v, want %v", dbType, got, expectedSupported) |
| 43 | + } |
| 44 | + }) |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +func TestCheckDBTypeIfDataExportSupported_UnsupportedTypes(t *testing.T) { |
| 49 | + // 验证未支持的类型返回 false |
| 50 | + unsupportedTypes := map[string]bool{ |
| 51 | + "MongoDB": false, |
| 52 | + "Redis": false, |
| 53 | + "UnknownDB": false, |
| 54 | + "": false, |
| 55 | + } |
| 56 | + for dbType, expectedSupported := range unsupportedTypes { |
| 57 | + t.Run(dbType, func(t *testing.T) { |
| 58 | + got := CheckDBTypeIfDataExportSupported(dbType) |
| 59 | + if got != expectedSupported { |
| 60 | + t.Errorf("CheckDBTypeIfDataExportSupported(%q) = %v, want %v", dbType, got, expectedSupported) |
| 61 | + } |
| 62 | + }) |
| 63 | + } |
| 64 | +} |
0 commit comments