@@ -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,52 @@ 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+ & pkgParams.Param {Key : redisTLSEnabledParam , Value : "true" , Type : pkgParams .ParamTypeBool },
154+ & pkgParams.Param {Key : redisTLSInsecureParam , Value : "true" , Type : pkgParams .ParamTypeBool },
155+ & pkgParams.Param {Key : redisScanCountParam , Value : "200" , Type : pkgParams .ParamTypeString },
156+ & pkgParams.Param {Key : redisKeySeparatorParam , Value : ":" , Type : pkgParams .ParamTypeString },
157+ & pkgParams.Param {Key : redisCommandTimeoutParam , Value : "3000" , Type : pkgParams .ParamTypeString },
158+ },
159+ })
160+ if defaultSchema == nil || * defaultSchema != defaultDB {
161+ t .Fatalf ("unexpected default schema: %#v" , defaultSchema )
162+ }
163+ if propertiesValue != nil {
164+ t .Fatalf ("expected nil properties, got %#v" , propertiesValue )
165+ }
166+ if jdbcParams ["defaultDatabase" ] != defaultDB || jdbcParams ["tls" ] != true || jdbcParams ["tlsInsecure" ] != true {
167+ t .Fatalf ("unexpected redis base params: %#v" , jdbcParams )
168+ }
169+ if jdbcParams ["scanCount" ] != "200" || jdbcParams ["keySeparator" ] != ":" || jdbcParams ["commandTimeoutMs" ] != "3000" {
170+ t .Fatalf ("unexpected redis tuning params: %#v" , jdbcParams )
171+ }
172+ }
173+
174+ func Test_buildRedisDatasourceOptions_noSensitiveProperties (t * testing.T ) {
175+ _ , propertiesValue , jdbcParams := buildRedisDatasourceOptions (& biz.DBService {
176+ DBType : string (pkgConst .DBTypeRedis ),
177+ User : "default" ,
178+ Password : "secret" ,
179+ AdditionalParams : pkgParams.Params {
180+ & pkgParams.Param {Key : redisTLSEnabledParam , Value : "false" , Type : pkgParams .ParamTypeBool },
181+ },
182+ })
183+ if propertiesValue != nil {
184+ t .Fatalf ("expected redis properties to stay nil, got %#v" , propertiesValue )
185+ }
186+ if _ , ok := jdbcParams ["password" ]; ok {
187+ t .Fatalf ("redis password leaked into jdbc params: %#v" , jdbcParams )
188+ }
189+ }
190+
143191// Test_buildDatasourceBaseInfo_DB2 覆盖 buildDatasourceBaseInfo 中 DB2 / 回归 4 组 case:
144192//
145193// (a) DB2 正例:AdditionalParam database_name=testdb → baseInfo.DefaultSchema=="testdb"
@@ -154,11 +202,11 @@ func Test_buildDatasourceBaseInfo_DB2(t *testing.T) {
154202 const datasourceName = "proj:ds"
155203
156204 cases := map [string ]struct {
157- dbService * biz.DBService
158- expectErr bool
159- expectErrSubstr string
160- expectDefaultSchema * string
161- expectServiceName * string
205+ dbService * biz.DBService
206+ expectErr bool
207+ expectErrSubstr string
208+ expectDefaultSchema * string
209+ expectServiceName * string
162210 }{
163211 "DB2 happy path" : {
164212 dbService : & biz.DBService {
0 commit comments