mirror of
https://github.com/usememos/memos.git
synced 2024-12-21 02:01:55 +03:00
41eba71f0f
* Add new database interface for SQL operations * Move SQL code of Activity into Database * Rename `Database` into `Driver` * Move SQL code of SystemSetting into Driver * Fix store.New in text code * Change database into driver in the variables * Change sqlite3.New into sqlite3.NewDriver
32 lines
694 B
Go
32 lines
694 B
Go
package teststore
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/usememos/memos/store"
|
|
"github.com/usememos/memos/store/db"
|
|
"github.com/usememos/memos/store/sqlite3"
|
|
"github.com/usememos/memos/test"
|
|
|
|
// sqlite driver.
|
|
_ "modernc.org/sqlite"
|
|
)
|
|
|
|
func NewTestingStore(ctx context.Context, t *testing.T) *store.Store {
|
|
profile := test.GetTestingProfile(t)
|
|
db := db.NewDB(profile)
|
|
if err := db.Open(); err != nil {
|
|
fmt.Printf("failed to open db, error: %+v\n", err)
|
|
}
|
|
if err := db.Migrate(ctx); err != nil {
|
|
fmt.Printf("failed to migrate db, error: %+v\n", err)
|
|
}
|
|
|
|
driver := sqlite3.NewDriver(db.DBInstance)
|
|
|
|
store := store.New(db.DBInstance, driver, profile)
|
|
return store
|
|
}
|