diff --git a/manager/database.go b/manager/database.go index 1550549..404a69d 100644 --- a/manager/database.go +++ b/manager/database.go @@ -24,14 +24,14 @@ func boolSetting(source, param string, ok bool) string { func timeSetting(source, param string, t time.Duration) string { //make sure 1ms<=t<24h if t < time.Millisecond || t >= 24*time.Hour { - return "" + return source } return fmt.Sprintf(cDSNFormat, source, param, t) } func stringSetting(source, param, value string) string { if "" == value { - return "" + return source } return fmt.Sprintf(cDSNFormat, source, param, value) } diff --git a/manager/database_test.go b/manager/database_test.go index 16a43b9..a1aa9bd 100644 --- a/manager/database_test.go +++ b/manager/database_test.go @@ -48,14 +48,16 @@ func TestConcatDSN_Time(t *testing.T) { func TestConcatDSN_Time_overflow(t *testing.T) { var setting []Setting ass := assert.New(t) - setting = append(setting, SetReadTimeout(time.Microsecond), SetTimeout(24*time.Hour)) - ass.Equal("", concatDSN(setting), "duration <1ms or >=24h should be invalid") + setting = append(setting, SetWriteTimeout(time.Minute), SetReadTimeout(time.Microsecond), SetTimeout(24*time.Hour)) + ass.Equal("writeTimeout=1m0s", concatDSN(setting), "duration <1ms or >=24h should be invalid") } func TestConcatDSN_String_null(t *testing.T) { var setting []Setting ass := assert.New(t) - setting = append(setting, SetCollation(""), SetLoc(""), SetStrict(false), SetInterpolateParams(true)) + setting = append([]Setting{}, SetCollation(""), SetLoc(""), SetStrict(false), SetInterpolateParams(true)) + ass.Equal("strict=false&interpolateParams=true", concatDSN(setting), `null value should be ignored`) + setting = append([]Setting{}, SetCollation(""), SetStrict(false), SetInterpolateParams(true), SetLoc("")) ass.Equal("strict=false&interpolateParams=true", concatDSN(setting), `null value should be ignored`) }