Unify webpush store tests across SQLite and PostgreSQL backends

Share test logic in store_test.go with thin per-backend wrappers.
Add SetSubscriptionUpdatedAt to both stores, removing the need for
raw SQL and the DB() accessor in tests.
This commit is contained in:
binwiederhier
2026-02-16 12:38:00 -05:00
parent e432bf2886
commit 5331437664
6 changed files with 233 additions and 333 deletions

View File

@@ -101,11 +101,6 @@ func NewSQLiteStore(filename, startupQueries string) (*SQLiteStore, error) {
}, nil
}
// DB returns the underlying database connection. This is exported for testing purposes.
func (c *SQLiteStore) DB() *sql.DB {
return c.db
}
func setupSQLiteWebPushDB(db *sql.DB) error {
// If 'schemaVersion' table does not exist, this must be a new database
rows, err := db.Query(sqliteSelectWebPushSchemaVersionQuery)
@@ -256,6 +251,13 @@ func (c *SQLiteStore) RemoveExpiredSubscriptions(expireAfter time.Duration) erro
return err
}
// SetSubscriptionUpdatedAt updates the updated_at timestamp for a subscription by endpoint. This is
// exported for testing purposes and is not part of the Store interface.
func (c *SQLiteStore) SetSubscriptionUpdatedAt(endpoint string, updatedAt int64) error {
_, err := c.db.Exec("UPDATE subscription SET updated_at = ? WHERE endpoint = ?", updatedAt, endpoint)
return err
}
// Close closes the underlying database connection.
func (c *SQLiteStore) Close() error {
return c.db.Close()