2019-12-17 19:29:43 +01:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2020-03-31 18:56:52 +02:00
|
|
|
"os"
|
2019-12-17 19:29:43 +01:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewSettings(t *testing.T) {
|
|
|
|
c := NewSettings()
|
2020-09-06 14:18:40 +02:00
|
|
|
|
2019-12-17 19:29:43 +01:00
|
|
|
assert.IsType(t, new(Settings), c)
|
|
|
|
}
|
|
|
|
|
2020-03-28 21:44:30 +01:00
|
|
|
func TestSettings_Load(t *testing.T) {
|
2019-12-17 19:29:43 +01:00
|
|
|
t.Run("existing filename", func(t *testing.T) {
|
|
|
|
c := NewSettings()
|
|
|
|
|
2020-12-13 14:53:26 +01:00
|
|
|
if err := c.Load("testdata/settings.yml"); err != nil {
|
2020-09-06 14:18:40 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-12-17 19:29:43 +01:00
|
|
|
|
2020-12-13 14:53:26 +01:00
|
|
|
assert.Equal(t, "onyx", c.UI.Theme)
|
|
|
|
assert.Equal(t, "de", c.UI.Language)
|
2019-12-17 19:29:43 +01:00
|
|
|
})
|
|
|
|
t.Run("not existing filename", func(t *testing.T) {
|
|
|
|
c := NewSettings()
|
|
|
|
|
2020-12-13 14:53:26 +01:00
|
|
|
err := c.Load("testdata/settings_123.yml")
|
2019-12-17 19:29:43 +01:00
|
|
|
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
2020-12-13 14:53:26 +01:00
|
|
|
assert.Equal(t, "default", c.UI.Theme)
|
|
|
|
assert.Equal(t, "en", c.UI.Language)
|
2019-12-17 19:29:43 +01:00
|
|
|
})
|
|
|
|
}
|
2020-03-28 21:44:30 +01:00
|
|
|
func TestSettings_Save(t *testing.T) {
|
2019-12-17 19:29:43 +01:00
|
|
|
t.Run("existing filename", func(t *testing.T) {
|
|
|
|
c := NewSettings()
|
|
|
|
|
2020-12-13 14:53:26 +01:00
|
|
|
assert.Equal(t, "default", c.UI.Theme)
|
|
|
|
assert.Equal(t, "en", c.UI.Language)
|
2019-12-17 19:29:43 +01:00
|
|
|
|
2020-12-13 14:53:26 +01:00
|
|
|
c.UI.Theme = "onyx"
|
|
|
|
c.UI.Language = "de"
|
|
|
|
|
|
|
|
assert.Equal(t, "onyx", c.UI.Theme)
|
|
|
|
assert.Equal(t, "de", c.UI.Language)
|
|
|
|
|
|
|
|
if err := c.Save("testdata/settings.yml"); err != nil {
|
2020-09-06 14:18:40 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-12-17 19:29:43 +01:00
|
|
|
})
|
|
|
|
t.Run("not existing filename", func(t *testing.T) {
|
|
|
|
c := NewSettings()
|
2020-12-13 14:53:26 +01:00
|
|
|
c.UI.Theme = "onyx"
|
|
|
|
c.UI.Language = "de"
|
2019-12-17 19:29:43 +01:00
|
|
|
|
2020-12-13 14:53:26 +01:00
|
|
|
assert.Equal(t, "onyx", c.UI.Theme)
|
|
|
|
assert.Equal(t, "de", c.UI.Language)
|
2019-12-17 19:29:43 +01:00
|
|
|
|
2020-12-13 14:53:26 +01:00
|
|
|
if err := c.Save("testdata/settings_tmp.yml"); err != nil {
|
2020-03-31 18:56:52 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-12-13 14:53:26 +01:00
|
|
|
if err := os.Remove("testdata/settings_tmp.yml"); err != nil {
|
2020-03-31 18:56:52 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2019-12-17 19:29:43 +01:00
|
|
|
})
|
|
|
|
}
|
2021-02-18 11:41:51 +01:00
|
|
|
|
|
|
|
func TestSettings_Stacks(t *testing.T) {
|
|
|
|
c := NewSettings()
|
|
|
|
assert.False(t, c.StackSequences())
|
|
|
|
assert.True(t, c.StackUUID())
|
|
|
|
assert.True(t, c.StackMeta())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfig_Settings(t *testing.T) {
|
|
|
|
c := TestConfig()
|
|
|
|
c.options.DisablePlaces = true
|
|
|
|
r := c.Settings()
|
|
|
|
assert.False(t, r.Features.Places)
|
|
|
|
}
|