mirror of
https://github.com/nkanaev/yarr.git
synced 2026-06-24 09:05:16 +00:00
storage test fixes
This commit is contained in:
@@ -156,6 +156,21 @@ func (s Settings) Map() map[string]any {
|
||||
}
|
||||
}
|
||||
|
||||
func SettingsDefault() Settings {
|
||||
return Settings{
|
||||
Filter: "",
|
||||
Feed: "",
|
||||
FeedListWidth: 300,
|
||||
ItemListWidth: 300,
|
||||
SortNewestFirst: true,
|
||||
ThemeName: "light",
|
||||
ThemeFont: "",
|
||||
ThemeSize: 1,
|
||||
RefreshRate: 0,
|
||||
Language: "en",
|
||||
}
|
||||
}
|
||||
|
||||
type FeedState struct {
|
||||
FeedID int64
|
||||
LastRefreshed time.Time
|
||||
|
||||
@@ -7,23 +7,8 @@ import (
|
||||
"github.com/nkanaev/yarr/src/storage/model"
|
||||
)
|
||||
|
||||
func settingsDefaults() model.Settings {
|
||||
return model.Settings{
|
||||
Filter: "",
|
||||
Feed: "",
|
||||
FeedListWidth: 300,
|
||||
ItemListWidth: 300,
|
||||
SortNewestFirst: true,
|
||||
ThemeName: "light",
|
||||
ThemeFont: "",
|
||||
ThemeSize: 1,
|
||||
RefreshRate: 0,
|
||||
Language: "en",
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PostgresStorage) GetSettings() model.Settings {
|
||||
result := settingsDefaults()
|
||||
result := model.SettingsDefault()
|
||||
rows, err := s.db.Query(`select key, val from settings;`)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
|
||||
@@ -8,23 +8,8 @@ import (
|
||||
"github.com/nkanaev/yarr/src/storage/model"
|
||||
)
|
||||
|
||||
func settingsDefaults() model.Settings {
|
||||
return model.Settings{
|
||||
Filter: "",
|
||||
Feed: "",
|
||||
FeedListWidth: 300,
|
||||
ItemListWidth: 300,
|
||||
SortNewestFirst: true,
|
||||
ThemeName: "light",
|
||||
ThemeFont: "",
|
||||
ThemeSize: 1,
|
||||
RefreshRate: 0,
|
||||
Language: "en",
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SQLiteStorage) GetSettings() model.Settings {
|
||||
result := settingsDefaults()
|
||||
result := model.SettingsDefault()
|
||||
rows, err := s.db.Query(`select key, val from settings;`)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
func TestSettingsDefaults(t *testing.T) {
|
||||
dbtest(t, func(t *testing.T, s storage.Storage) {
|
||||
settings := s.GetSettings()
|
||||
defaults := settingsDefaults()
|
||||
defaults := model.SettingsDefault()
|
||||
|
||||
if !reflect.DeepEqual(settings, defaults) {
|
||||
t.Errorf("expected defaults %+v, got %+v", defaults, settings)
|
||||
@@ -49,7 +49,6 @@ func TestUpdateSettings(t *testing.T) {
|
||||
|
||||
func TestGetSettings(t *testing.T) {
|
||||
dbtest(t, func(t *testing.T, s storage.Storage) {
|
||||
|
||||
s.UpdateSettings(model.UpdateSettingsParams{Language: ptr("fr")})
|
||||
|
||||
settings := s.GetSettings()
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
func dbtest(t *testing.T, testcase func(t *testing.T, db storage.Storage)) {
|
||||
testurls := map[string]string{
|
||||
"sqlite": ":memory:",
|
||||
"postgres": "postgres://postgres:postgres@localhost:5432/yarr_test",
|
||||
"postgres": "postgres://postgres:postgres@localhost:5432/yarr_test?sslmode=disable",
|
||||
}
|
||||
for testname, url := range testurls {
|
||||
db, err := storage.New(url)
|
||||
|
||||
Reference in New Issue
Block a user