Skip to content

Commit 2db40fb

Browse files
committed
Fixed connection string
1 parent d77e75c commit 2db40fb

10 files changed

+14
-19
lines changed

internal/webserver/authentication_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
func TestAuthentication(t *testing.T) {
22-
db := infrastructure.Connect("file::memory:", 250)
22+
db := infrastructure.Connect(":memory:", 250)
2323
app := bootstrapApp(db, &infrastructure.SMTP{}, afero.NewMemMapFs(), webserver.Config{})
2424

2525
data := url.Values{
@@ -82,7 +82,7 @@ func TestAuthentication(t *testing.T) {
8282
}
8383

8484
func TestRecoverNoEmailService(t *testing.T) {
85-
db := infrastructure.Connect("file::memory:?cache=shared", 250)
85+
db := infrastructure.Connect(":memory:?cache=shared", 250)
8686
app := bootstrapApp(db, &infrastructure.NoEmail{}, afero.NewMemMapFs(), webserver.Config{})
8787

8888
req, err := http.NewRequest(http.MethodGet, "/en/recover", nil)
@@ -115,7 +115,7 @@ func TestRecover(t *testing.T) {
115115
LibraryPath: "fixtures/library",
116116
UploadDocumentMaxSize: 1,
117117
}
118-
db = infrastructure.Connect("file::memory:?cache=shared", 250)
118+
db = infrastructure.Connect(":memory:?cache=shared", 250)
119119
smtpMock = &infrastructure.SMTPMock{}
120120
app = bootstrapApp(db, smtpMock, afero.NewMemMapFs(), webserverConfig)
121121

internal/webserver/document_detail_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
func TestDocumentAndRead(t *testing.T) {
13-
db := infrastructure.Connect("file::memory:", 250)
13+
db := infrastructure.Connect(":memory:", 250)
1414
smtpMock := &infrastructure.SMTPMock{}
1515
app := bootstrapApp(db, smtpMock, afero.NewOsFs(), webserver.Config{})
1616

internal/webserver/highlights_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestHighlights(t *testing.T) {
2727
reset := func() {
2828
var err error
2929

30-
db = infrastructure.Connect("file::memory:", 250)
30+
db = infrastructure.Connect(":memory:", 250)
3131
appFS := loadFilesInMemoryFs([]string{"fixtures/library/metadata.epub"})
3232
app = bootstrapApp(db, &infrastructure.NoEmail{}, appFS, webserver.Config{})
3333
adminCookie, err = login(app, "[email protected]", "admin", t)

internal/webserver/infrastructure/sqlite.go

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package infrastructure
22

33
import (
4+
"fmt"
45
"log"
56
"os"
67
"strings"
@@ -12,24 +13,18 @@ import (
1213
)
1314

1415
func Connect(path string, wordsPerMinute float64) *gorm.DB {
15-
if _, err := os.Stat(path); os.IsNotExist(err) && !strings.Contains(path, "file::memory") {
16+
if _, err := os.Stat(path); os.IsNotExist(err) && !strings.Contains(path, ":memory:") {
1617
if _, err = os.Create(path); err != nil {
1718
log.Fatal(err)
1819
}
1920
log.Printf("Created database at %s\n", path)
2021
}
2122

22-
// Use the following line to connect when the temporary code block below is removed
23-
//db, err := gorm.Open(sqlite.Open(fmt.Sprintf("%s?_pragma=foreign_keys(1)", path)), &gorm.Config{})
24-
db, err := gorm.Open(sqlite.Open(path), &gorm.Config{})
23+
db, err := gorm.Open(sqlite.Open(fmt.Sprintf("%s?_pragma=foreign_keys(1)", path)), &gorm.Config{})
2524
if err != nil {
2625
log.Fatal(err)
2726
}
2827

29-
if res := db.Exec("PRAGMA foreign_keys(1)", nil); res.Error != nil {
30-
log.Fatal(err)
31-
}
32-
3328
if err := db.AutoMigrate(&model.User{}, &model.Highlight{}); err != nil {
3429
log.Fatal(err)
3530
}

internal/webserver/remove_document_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
func TestRemoveDocument(t *testing.T) {
18-
db := infrastructure.Connect("file::memory:", 250)
18+
db := infrastructure.Connect(":memory:", 250)
1919
smtpMock := &infrastructure.SMTPMock{}
2020
appFS := loadDirInMemoryFs("fixtures/library")
2121
app := bootstrapApp(db, smtpMock, appFS, webserver.Config{})

internal/webserver/search_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
func TestSearch(t *testing.T) {
14-
db := infrastructure.Connect("file::memory:", 250)
14+
db := infrastructure.Connect(":memory:", 250)
1515
smtpMock := &infrastructure.SMTPMock{}
1616
appFS := loadDirInMemoryFs("fixtures/library")
1717

internal/webserver/send_document_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func TestSendDocument(t *testing.T) {
15-
db := infrastructure.Connect("file::memory:", 250)
15+
db := infrastructure.Connect(":memory:", 250)
1616
smtpMock := &infrastructure.SMTPMock{}
1717
app := bootstrapApp(db, smtpMock, afero.NewOsFs(), webserver.Config{})
1818

internal/webserver/upload_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
func TestUpload(t *testing.T) {
22-
db := infrastructure.Connect("file::memory:", 250)
22+
db := infrastructure.Connect(":memory:", 250)
2323
appFS := loadDirInMemoryFs("fixtures/library")
2424
app := bootstrapApp(db, &infrastructure.NoEmail{}, appFS, webserver.Config{})
2525

internal/webserver/user_management_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestUserManagement(t *testing.T) {
3232
t.Helper()
3333

3434
var err error
35-
db = infrastructure.Connect("file::memory:", 250)
35+
db = infrastructure.Connect(":memory:", 250)
3636
app = bootstrapApp(db, &infrastructure.NoEmail{}, afero.NewMemMapFs(), webserver.Config{})
3737

3838
adminUser = model.User{}

internal/webserver/webserver_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestGET(t *testing.T) {
3535
{"Server returns not found if the user tries to access a non-existent URL", "/xx", http.StatusNotFound},
3636
}
3737

38-
db := infrastructure.Connect("file::memory:", 250)
38+
db := infrastructure.Connect(":memory:", 250)
3939
app := bootstrapApp(db, &infrastructure.NoEmail{}, afero.NewMemMapFs(), webserver.Config{})
4040

4141
for _, tcase := range cases {

0 commit comments

Comments
 (0)