photoprism/internal/config/settings_test.go

86 lines
1.7 KiB
Go
Raw Normal View History

2019-12-17 19:29:43 +01:00
package config
import (
"os"
2019-12-17 19:29:43 +01:00
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewSettings(t *testing.T) {
c := NewSettings()
2019-12-17 19:29:43 +01:00
assert.IsType(t, new(Settings), c)
}
func TestSettings_Load(t *testing.T) {
2019-12-17 19:29:43 +01:00
t.Run("existing filename", func(t *testing.T) {
c := NewSettings()
if err := c.Load("testdata/settings.yml"); err != nil {
t.Fatal(err)
}
2019-12-17 19:29:43 +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()
err := c.Load("testdata/settings_123.yml")
2019-12-17 19:29:43 +01:00
assert.Error(t, err)
assert.Equal(t, "default", c.UI.Theme)
assert.Equal(t, "en", c.UI.Language)
2019-12-17 19:29:43 +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()
assert.Equal(t, "default", c.UI.Theme)
assert.Equal(t, "en", c.UI.Language)
2019-12-17 19:29:43 +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 {
t.Fatal(err)
}
2019-12-17 19:29:43 +01:00
})
t.Run("not existing filename", func(t *testing.T) {
c := NewSettings()
c.UI.Theme = "onyx"
c.UI.Language = "de"
2019-12-17 19:29:43 +01:00
assert.Equal(t, "onyx", c.UI.Theme)
assert.Equal(t, "de", c.UI.Language)
2019-12-17 19:29:43 +01:00
if err := c.Save("testdata/settings_tmp.yml"); err != nil {
t.Fatal(err)
}
if err := os.Remove("testdata/settings_tmp.yml"); err != nil {
t.Fatal(err)
}
2019-12-17 19:29:43 +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)
}