fix(setting): honor bare -1 for timeout settings (#39181)

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
aminoy
2026-08-31 19:48:59 +00:00
committed by GitHub
co-authored by wxiaoguang
parent 70678e9a3d
commit fc9800b383
12 changed files with 130 additions and 58 deletions
+13
View File
@@ -6,6 +6,7 @@ package setting
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
@@ -136,3 +137,15 @@ func TestDisableSaving(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "k1 = a\nk2 = y\nk3 = z\n", string(bs))
}
func TestConfigValueRead(t *testing.T) {
cfg, _ := NewConfigProviderFromData(`
neg = -1
zero = 0
hour = 1h
`)
assert.Equal(t, -1*time.Second, cfg.Section("").Key("neg").MustDuration(9999))
assert.EqualValues(t, 0, cfg.Section("").Key("zero").MustDuration(9999))
assert.Equal(t, time.Hour, cfg.Section("").Key("hour").MustDuration(9999))
assert.Equal(t, time.Duration(9999), cfg.Section("").Key("def").MustDuration(9999))
}