45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package store
|
|
|
|
import (
|
|
"errors"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestSettings(t *testing.T) {
|
|
s, _ := openTest(t)
|
|
if _, err := s.Setting(ctx, "public_url"); !errors.Is(err, ErrNotFound) {
|
|
t.Errorf("fehlende Einstellung: erwartet ErrNotFound, bekommen %v", err)
|
|
}
|
|
if err := s.SetSetting(ctx, "public_url", "https://a.example:8443"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := s.SetSetting(ctx, "public_url", "https://b.example:8443"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if v, err := s.Setting(ctx, "public_url"); err != nil || v != "https://b.example:8443" {
|
|
t.Errorf("Setting = %q, %v", v, err)
|
|
}
|
|
if err := s.SetSetting(ctx, "", "x"); !errors.Is(err, ErrInvalid) {
|
|
t.Errorf("leerer Schlüssel: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestSettings_SurviveReopen(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "sultan.db")
|
|
s, err := Open(ctx, path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
s.SetSetting(ctx, "public_url", "https://a.example:8443")
|
|
s.Close()
|
|
s, _ = Open(ctx, path)
|
|
defer s.Close()
|
|
if v, _ := s.Setting(ctx, "public_url"); v != "https://a.example:8443" {
|
|
t.Errorf("nach Neustart: %q", v)
|
|
}
|
|
if v, _ := s.SchemaVersion(ctx); v < 2 {
|
|
t.Errorf("Schema-Version %d, erwartet mindestens 2", v)
|
|
}
|
|
}
|