Skip to content

Commit 5f80f16

Browse files
committed
feat: extend data export whitelist for TiDB/TDSQL/GoldenDB/TBase/GaussDB/openGauss/DB2 (#593)
1 parent 3e96b9e commit 5f80f16

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

internal/dms/pkg/constant/const.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,13 @@ var supportedDataExportDBTypes = map[DBType]struct{}{
280280
DBTypeOceanBaseMySQL: {},
281281
DBTypeHive: {},
282282
DBTypeDM: {},
283+
// 新增数据源 (Issue #593)
284+
DBTypeTiDB: {},
285+
DBTypeTDSQLForInnoDB: {},
286+
DBTypeGoldenDB: {},
287+
DBTypeTBase: {},
288+
DBTypeGaussDB: {},
289+
DBTypeDB2: {},
283290
}
284291

285292
func CheckDBTypeIfDataExportSupported(dbtype string) bool {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)