From a4d2052c659f130da863baae095df80bfc84cfe0 Mon Sep 17 00:00:00 2001 From: WeizhongTu Date: Fri, 11 Aug 2023 11:32:04 +0800 Subject: [PATCH 1/2] fix manager blank --- manager/database.go | 4 ++-- manager/database_test.go | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) 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..df1621a 100644 --- a/manager/database_test.go +++ b/manager/database_test.go @@ -48,8 +48,8 @@ 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) { @@ -57,6 +57,8 @@ func TestConcatDSN_String_null(t *testing.T) { ass := assert.New(t) 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`) } func TestNew(t *testing.T) { From 030dc921fe290addbda47aea0d42ae77802839c4 Mon Sep 17 00:00:00 2001 From: WeizhongTu Date: Fri, 11 Aug 2023 21:30:19 +0800 Subject: [PATCH 2/2] fix unit tests --- manager/database_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manager/database_test.go b/manager/database_test.go index df1621a..a1aa9bd 100644 --- a/manager/database_test.go +++ b/manager/database_test.go @@ -55,9 +55,9 @@ func TestConcatDSN_Time_overflow(t *testing.T) { 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("")) + setting = append([]Setting{}, SetCollation(""), SetStrict(false), SetInterpolateParams(true), SetLoc("")) ass.Equal("strict=false&interpolateParams=true", concatDSN(setting), `null value should be ignored`) }