photoprism/internal/config/settings_test.go

69 lines
1.3 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()
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()
err := c.Load("testdata/config.yml")
2019-12-17 19:29:43 +01:00
assert.Nil(t, err)
assert.Equal(t, "lavendel", c.Theme)
assert.Equal(t, "english", c.Language)
})
t.Run("not existing filename", func(t *testing.T) {
c := NewSettings()
err := c.Load("testdata/config123.yml")
2019-12-17 19:29:43 +01:00
assert.Error(t, err)
assert.Equal(t, "default", c.Theme)
assert.Equal(t, "en", c.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()
c.Theme = "lavendel"
c.Language = "german"
assert.Equal(t, "lavendel", c.Theme)
assert.Equal(t, "german", c.Language)
err := c.Save("testdata/configEmpty.yml")
2019-12-17 19:29:43 +01:00
assert.Nil(t, err)
})
t.Run("not existing filename", func(t *testing.T) {
c := NewSettings()
c.Theme = "lavendel"
c.Language = "german"
assert.Equal(t, "lavendel", c.Theme)
assert.Equal(t, "german", c.Language)
err := c.Save("testdata/configEmpty123.yml")
2019-12-17 19:29:43 +01:00
if err != nil {
t.Fatal(err)
}
if err := os.Remove("testdata/configEmpty123.yml"); err != nil {
t.Fatal(err)
}
2019-12-17 19:29:43 +01:00
})
}