@@ -28,6 +28,7 @@ func Test_convertDBType(t *testing.T) {
2828 "PolarDB For MySQL" : {input : "PolarDB For MySQL" , expected : "MYSQL" },
2929 "GaussDB" : {input : "GaussDB" , expected : "GAUSSDB" },
3030 "MongoDB" : {input : "MongoDB" , expected : "MONGODB" },
31+ "Redis" : {input : "Redis" , expected : "REDIS" },
3132 "DB2" : {input : "DB2" , expected : "DB2" },
3233 "Unknown passthrough" : {input : "UnknownDB" , expected : "UnknownDB" },
3334 }
@@ -55,6 +56,7 @@ func Test_SupportDBType(t *testing.T) {
5556 "TDSQL supported" : {input : pkgConst .DBTypeTDSQLForInnoDB , expected : true },
5657 "GoldenDB supported" : {input : pkgConst .DBTypeGoldenDB , expected : true },
5758 "MongoDB unsupported" : {input : pkgConst .DBTypeMongoDB , expected : false },
59+ "Redis supported" : {input : pkgConst .DBTypeRedis , expected : true },
5860 "PostgreSQL supported" : {input : pkgConst .DBTypePostgreSQL , expected : true },
5961 "SQL Server unsupported" : {input : pkgConst .DBTypeSQLServer , expected : false },
6062 "PolarDB For MySQL supported" : {input : pkgConst .DBTypePolarDBForMySQL , expected : true },
@@ -140,6 +142,44 @@ func Test_buildMongoDatasourceOptions_tlsOnly(t *testing.T) {
140142 }
141143}
142144
145+ func Test_buildRedisDatasourceOptions (t * testing.T ) {
146+ defaultDB := "2"
147+ defaultSchema , propertiesValue , jdbcParams := buildRedisDatasourceOptions (& biz.DBService {
148+ DBType : string (pkgConst .DBTypeRedis ),
149+ Host : "127.0.0.1" ,
150+ Port : "6379" ,
151+ AdditionalParams : pkgParams.Params {
152+ & pkgParams.Param {Key : redisDefaultDatabaseParam , Value : defaultDB , Type : pkgParams .ParamTypeString },
153+ },
154+ })
155+ if defaultSchema == nil || * defaultSchema != defaultDB {
156+ t .Fatalf ("unexpected default schema: %#v" , defaultSchema )
157+ }
158+ if propertiesValue != nil {
159+ t .Fatalf ("expected nil properties, got %#v" , propertiesValue )
160+ }
161+ if jdbcParams ["defaultDatabase" ] != defaultDB {
162+ t .Fatalf ("unexpected redis jdbc params: %#v" , jdbcParams )
163+ }
164+ }
165+
166+ func Test_buildRedisDatasourceOptions_noSensitiveProperties (t * testing.T ) {
167+ _ , propertiesValue , jdbcParams := buildRedisDatasourceOptions (& biz.DBService {
168+ DBType : string (pkgConst .DBTypeRedis ),
169+ User : "default" ,
170+ Password : "secret" ,
171+ AdditionalParams : pkgParams.Params {
172+ & pkgParams.Param {Key : redisDefaultDatabaseParam , Value : "0" , Type : pkgParams .ParamTypeString },
173+ },
174+ })
175+ if propertiesValue != nil {
176+ t .Fatalf ("expected redis properties to stay nil, got %#v" , propertiesValue )
177+ }
178+ if _ , ok := jdbcParams ["password" ]; ok {
179+ t .Fatalf ("redis password leaked into jdbc params: %#v" , jdbcParams )
180+ }
181+ }
182+
143183// Test_buildDatasourceBaseInfo_DB2 覆盖 buildDatasourceBaseInfo 中 DB2 / 回归 4 组 case:
144184//
145185// (a) DB2 正例:AdditionalParam database_name=testdb → baseInfo.DefaultSchema=="testdb"
@@ -154,11 +194,11 @@ func Test_buildDatasourceBaseInfo_DB2(t *testing.T) {
154194 const datasourceName = "proj:ds"
155195
156196 cases := map [string ]struct {
157- dbService * biz.DBService
158- expectErr bool
159- expectErrSubstr string
160- expectDefaultSchema * string
161- expectServiceName * string
197+ dbService * biz.DBService
198+ expectErr bool
199+ expectErrSubstr string
200+ expectDefaultSchema * string
201+ expectServiceName * string
162202 }{
163203 "DB2 happy path" : {
164204 dbService : & biz.DBService {
0 commit comments