2020-09-15 08:20:53 -05:00
|
|
|
package setting
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"gopkg.in/ini.v1"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-11-09 07:39:56 -06:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-09-15 08:20:53 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestValueAsTimezone(t *testing.T) {
|
|
|
|
tests := map[string]struct {
|
|
|
|
output string
|
|
|
|
hasErr bool
|
|
|
|
}{
|
|
|
|
"browser": {"browser", false},
|
|
|
|
"UTC": {"UTC", false},
|
|
|
|
"Amsterdam": {"browser", true},
|
|
|
|
"Europe/Amsterdam": {"Europe/Amsterdam", false},
|
|
|
|
}
|
|
|
|
|
|
|
|
sec, err := ini.Empty().NewSection("test")
|
2020-11-09 07:39:56 -06:00
|
|
|
require.NoError(t, err)
|
2020-09-15 08:20:53 -05:00
|
|
|
key, err := sec.NewKey("test", "")
|
2020-11-09 07:39:56 -06:00
|
|
|
require.NoError(t, err)
|
2020-09-15 08:20:53 -05:00
|
|
|
|
|
|
|
for input, expected := range tests {
|
|
|
|
key.SetValue(input)
|
|
|
|
|
2020-11-09 07:39:56 -06:00
|
|
|
output, err := valueAsTimezone(sec, "test")
|
2020-09-15 08:20:53 -05:00
|
|
|
|
2020-11-09 07:39:56 -06:00
|
|
|
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)
|
2020-09-15 08:20:53 -05:00
|
|
|
}
|
|
|
|
}
|