Use sql database instead of bolt
This commit is contained in:
@@ -13,9 +13,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.hashru.nl/dsprenkels/rushlink/internal/boltdb"
|
||||
"gitea.hashru.nl/dsprenkels/rushlink/internal/db"
|
||||
"github.com/gorilla/mux"
|
||||
"go.etcd.io/bbolt"
|
||||
)
|
||||
|
||||
// createTemporaryRouter initializes a rushlink instance, with temporary
|
||||
@@ -31,20 +30,22 @@ func createTemporaryRouter(t *testing.T) (*mux.Router, *rushlink) {
|
||||
os.RemoveAll(tempDir)
|
||||
})
|
||||
|
||||
fileStore, err := boltdb.OpenFileStore(filepath.Join(tempDir, "filestore"))
|
||||
fileStore, err := db.OpenFileStore(filepath.Join(tempDir, "filestore"))
|
||||
if err != nil {
|
||||
t.Fatalf("opening temporary filestore: %s\n", err)
|
||||
}
|
||||
databasePath := filepath.Join(tempDir, "rushlink.db")
|
||||
database, err := boltdb.OpenDB(databasePath, fileStore)
|
||||
|
||||
os.Setenv(db.EnvDatabaseDriver, "sqlite")
|
||||
os.Setenv(db.EnvDatabasePath, "file::memory:?cache=shared")
|
||||
|
||||
database, err := db.OpenDBFromEnvironment()
|
||||
if err != nil {
|
||||
t.Fatalf("opening temporary database: %s\n", err)
|
||||
t.Fatalf("opening temporary database: %v\n", err)
|
||||
}
|
||||
database.Debug()
|
||||
if err := db.Gormigrate(database).Migrate(); err != nil {
|
||||
t.Fatalf("migration failed: %v\n", err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if err := database.Close(); err != nil {
|
||||
t.Errorf("closing database: %d\n", err)
|
||||
}
|
||||
})
|
||||
|
||||
// *.invalid. is guaranteed not to exist (RFC 6761).
|
||||
rootURL, err := url.Parse("https://rushlink.invalid")
|
||||
@@ -135,8 +136,8 @@ func TestIssue53(t *testing.T) {
|
||||
checkStatusCode(t, rr, http.StatusFound)
|
||||
|
||||
// Check that any attempt to do directory traversal has failed.
|
||||
rl.db.Bolt.View(func(tx *bbolt.Tx) error {
|
||||
fus, err := boltdb.AllFileUploads(tx)
|
||||
rl.db.Transaction(func(tx *db.Database) error {
|
||||
fus, err := db.AllFileUploads(tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user