mirror of
https://github.com/go-shiori/shiori.git
synced 2025-10-06 19:47:16 +08:00
* refactor: base http server stdlib * refactor: swagger and frontend routes * fix: use global middlewares * refactor: removed gin from testutils * fix: object references in legacy webserver * refactor: legacy, swagger and system handlers * fix: added verbs to handlers * fix: server handlers ordering * refactor: bookmarks handlers * refactor: system api routes * tests: bookmark handlers * refactor: migrated api auth routes * chore: remove unused middlewares * docs: add swagger docs to refactored system api * chore: remove old auth routes * refactor: account apis * chore: removed old handlers * fix: api v1 handlers missing middlewares * refactor: migrated tag list route * refactor: bookmark routes * refactor: remove gin * chore: make styles * test: fixed tests * test: generate binary file without text * fix: global middleware missing from system api handler * fix: incorrect api handler * chore: avoid logging screenshot contents * tests: bookmarks domain * tests: shortcuts * test: missing tests * tests: server tests * test: remove test using syscall to avoid windows errors * chore: added middlewares
71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
package database
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/go-shiori/shiori/internal/model"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func sqliteTestDatabaseFactory(t *testing.T, ctx context.Context) (model.DB, error) {
|
|
tmpDir, err := os.MkdirTemp("", "")
|
|
require.NoError(t, err)
|
|
|
|
db, err := OpenSQLiteDatabase(ctx, filepath.Join(tmpDir, "shiori.db"))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err := db.Migrate(context.TODO()); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return db, nil
|
|
}
|
|
|
|
func TestSqliteDatabase(t *testing.T) {
|
|
testDatabase(t, sqliteTestDatabaseFactory)
|
|
testSqliteGetBookmarksWithDash(t)
|
|
}
|
|
|
|
// testSqliteGetBookmarksWithDash ad-hoc test for SQLite that checks that a match search against
|
|
// the FTS5 engine does not fail by using dashes, making sqlite think that we are trying to avoid
|
|
// matching a column name. This works in a fun way and it seems that it depends on the tokens
|
|
// already scanned by the database, since trying to match for `go-shiori` with no bookmarks or only
|
|
// the shiori bookmark does not fail, but it fails if we add any other bookmark to the database, hence
|
|
// this test.
|
|
func testSqliteGetBookmarksWithDash(t *testing.T) {
|
|
ctx := context.TODO()
|
|
|
|
db, err := sqliteTestDatabaseFactory(t, ctx)
|
|
assert.NoError(t, err)
|
|
|
|
book := model.BookmarkDTO{
|
|
URL: "https://github.com/go-shiori/shiori",
|
|
Title: "shiori",
|
|
}
|
|
|
|
_, err = db.SaveBookmarks(ctx, true, book)
|
|
assert.NoError(t, err, "Save bookmarks must not fail")
|
|
|
|
book = model.BookmarkDTO{
|
|
URL: "https://github.com/jamiehannaford/what-happens-when-k8s",
|
|
Title: "what-happens-when-k8s",
|
|
}
|
|
|
|
result, err := db.SaveBookmarks(ctx, true, book)
|
|
assert.NoError(t, err, "Save bookmarks must not fail")
|
|
savedBookmark := result[0]
|
|
|
|
results, err := db.GetBookmarks(ctx, model.DBGetBookmarksOptions{
|
|
Keyword: "what-happens-when",
|
|
})
|
|
|
|
assert.NoError(t, err, "Get bookmarks should not fail")
|
|
assert.Len(t, results, 1, "results should contain one item")
|
|
assert.Equal(t, savedBookmark.ID, results[0].ID, "bookmark should be the one saved")
|
|
}
|