mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
setting: Fix tests on Mac (#28886)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
parent
2ddda8f452
commit
ef2de2d357
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user