54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package config
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestApplicationSettingsPersistWithoutChangingGlobalProfile(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "settings.toml")
|
|
store, err := NewStore(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
global := DefaultSettings()
|
|
global.TimeFormat = "24-hour"
|
|
if err := store.Save(global); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
application := global
|
|
application.TimeFormat = "12-hour"
|
|
if err := store.SaveForApplication("Example Editor", application); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
other := global
|
|
other.DateFormat = "numbers-ymd"
|
|
if err := store.SaveForApplication("Other Editor", other); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
reopened, err := NewStore(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
loaded, err := reopened.Load()
|
|
if err != nil || loaded.TimeFormat != "24-hour" || loaded.ActiveProfile != "default" {
|
|
t.Fatalf("global = %+v, %v", loaded, err)
|
|
}
|
|
appLoaded, found, err := reopened.LoadForApplication("Example Editor")
|
|
if err != nil || !found || appLoaded.TimeFormat != "12-hour" {
|
|
t.Fatalf("application = %+v, found %t, %v", appLoaded, found, err)
|
|
}
|
|
missing, found, err := reopened.LoadForApplication("Unknown Editor")
|
|
if err != nil || found || missing.TimeFormat != "24-hour" {
|
|
t.Fatalf("unmapped = %+v, found %t, %v", missing, found, err)
|
|
}
|
|
global.DateFormat = "numbers-mdy"
|
|
if err := reopened.Save(global); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
appLoaded, found, err = reopened.LoadForApplication("Example Editor")
|
|
if err != nil || !found || appLoaded.TimeFormat != "12-hour" || appLoaded.DateFormat != "numbers-mdy" {
|
|
t.Fatalf("application after global save = %+v, found %t, %v", appLoaded, found, err)
|
|
}
|
|
}
|