Use sql database instead of bolt

This commit is contained in:
Daan Sprenkels
2020-10-25 17:33:51 +01:00
parent f36fa30eff
commit 0048004252
17 changed files with 1101 additions and 105 deletions

View File

@@ -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)
}