Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug: manager settings set blank value option missing #145

Merged
merged 2 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions manager/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 5 additions & 3 deletions manager/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
}

Expand Down
Loading