mirror of
https://github.com/aykhans/slash-e.git
synced 2025-06-15 12:27:49 +00:00
chore: update store testing
This commit is contained in:
@ -5,9 +5,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
// sqlite driver.
|
||||
_ "modernc.org/sqlite"
|
||||
|
||||
"github.com/yourselfhosted/slash/server/profile"
|
||||
"github.com/yourselfhosted/slash/store"
|
||||
"github.com/yourselfhosted/slash/store/db"
|
||||
test "github.com/yourselfhosted/slash/test"
|
||||
@ -19,15 +17,29 @@ func NewTestingStore(ctx context.Context, t *testing.T) *store.Store {
|
||||
if err != nil {
|
||||
fmt.Printf("failed to create db driver, error: %+v\n", err)
|
||||
}
|
||||
resetTestingDB(ctx, profile, dbDriver)
|
||||
if err := dbDriver.Migrate(ctx); err != nil {
|
||||
fmt.Printf("failed to migrate db, error: %+v\n", err)
|
||||
}
|
||||
if profile.Driver == "postgres" {
|
||||
if err := dbDriver.Seed(ctx); err != nil {
|
||||
fmt.Printf("failed to seed db, error: %+v\n", err)
|
||||
}
|
||||
}
|
||||
|
||||
store := store.New(dbDriver, profile)
|
||||
return store
|
||||
}
|
||||
|
||||
func resetTestingDB(ctx context.Context, profile *profile.Profile, dbDriver store.Driver) {
|
||||
if profile.Driver == "postgres" {
|
||||
_, err := dbDriver.GetDB().ExecContext(ctx, `
|
||||
DROP TABLE IF EXISTS migration_history CASCADE;
|
||||
DROP TABLE IF EXISTS workspace_setting CASCADE;
|
||||
DROP TABLE IF EXISTS "user" CASCADE;
|
||||
DROP TABLE IF EXISTS user_setting CASCADE;
|
||||
DROP TABLE IF EXISTS shortcut CASCADE;
|
||||
DROP TABLE IF EXISTS activity CASCADE;
|
||||
DROP TABLE IF EXISTS collection CASCADE;
|
||||
DROP TABLE IF EXISTS memo CASCADE;`)
|
||||
if err != nil {
|
||||
fmt.Printf("failed to reset testing db, error: %+v\n", err)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user