Skip to content

Commit

Permalink
Update test to use in memory database
Browse files Browse the repository at this point in the history
SQLite supports a special file path, :memory: which uses
an in-memory database. Thus, we use that for the test.
  • Loading branch information
amitsaha committed Jun 27, 2023
1 parent 0a4fb89 commit a054cc1
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions app_test.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
package main

import (
"os"
"path"
"reflect"
"testing"
)

func TestInsertAndQueryData(t *testing.T) {
dbPath := path.Join(t.TempDir(), "app.db")

// we close the DB connection
// and remove the DB path explicitly for Windows
// https://github.com/practicalgo/go-sqlite-demo/actions/runs/5319761510/jobs/9632645015
t.Cleanup(func() {
db.Close()
os.RemoveAll(dbPath)
})

err := initDatabase(dbPath)
err := initDatabase(":memory:")
if err != nil {
t.Fatal("error initializing database: ", err)
}
Expand Down

0 comments on commit a054cc1

Please sign in to comment.