Commit ef2de2d3 by Arve Knudsen Committed by GitHub

setting: Fix tests on Mac (#28886)

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
parent 2ddda8f4
......@@ -22,18 +22,17 @@ type DateFormatIntervals struct {
Year string `json:"year"`
}
const LocalBrowserTimezone = "browser"
const localBrowserTimezone = "browser"
func valueAsTimezone(section *ini.Section, keyName string, defaultValue string) (string, error) {
timezone := section.Key(keyName).MustString(defaultValue)
if timezone == LocalBrowserTimezone {
return LocalBrowserTimezone, nil
func valueAsTimezone(section *ini.Section, keyName string) (string, error) {
timezone := section.Key(keyName).MustString(localBrowserTimezone)
if timezone == localBrowserTimezone {
return localBrowserTimezone, nil
}
location, err := time.LoadLocation(timezone)
if err != nil {
return LocalBrowserTimezone, err
return localBrowserTimezone, err
}
return location.String(), nil
......@@ -50,7 +49,7 @@ func (cfg *Cfg) readDateFormats() {
cfg.DateFormats.Interval.Year = "YYYY"
cfg.DateFormats.UseBrowserLocale = dateFormats.Key("date_format_use_browser_locale").MustBool(false)
timezone, err := valueAsTimezone(dateFormats, "default_timezone", LocalBrowserTimezone)
timezone, err := valueAsTimezone(dateFormats, "default_timezone")
if err != nil {
cfg.Logger.Warn("Unknown timezone as default_timezone", "err", err)
}
......
......@@ -6,6 +6,7 @@ import (
"gopkg.in/ini.v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestValueAsTimezone(t *testing.T) {
......@@ -15,23 +16,21 @@ func TestValueAsTimezone(t *testing.T) {
}{
"browser": {"browser", false},
"UTC": {"UTC", false},
"utc": {"browser", true},
"Amsterdam": {"browser", true},
"europe/amsterdam": {"browser", true},
"Europe/Amsterdam": {"Europe/Amsterdam", false},
}
sec, err := ini.Empty().NewSection("test")
assert.NoError(t, err)
require.NoError(t, err)
key, err := sec.NewKey("test", "")
assert.NoError(t, err)
require.NoError(t, err)
for input, expected := range tests {
key.SetValue(input)
output, err := valueAsTimezone(sec, "test", "default")
output, err := valueAsTimezone(sec, "test")
assert.Equal(t, expected.hasErr, err != nil, "Invalid has err for input: %s err: %v", input, err)
assert.Equal(t, expected.output, output, "Invalid output for input: %s", input)
assert.Equal(t, expected.hasErr, err != nil, "Invalid has err for input %q: %s", input, err)
assert.Equal(t, expected.output, output, "Invalid output for input %q", input)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment