I modified my app recently and found that tests started hanging. This the stripped down test code:
package app_test
import (
"testing"
"github.com/kargirwar/prosql-go/db"
)
func TestApp(t *testing.T) {
db.SetDbPath("")
}
The db package is as follows:
package db
import (
"os"
"context"
"database/sql"
_ "github.com/mattn/go-sqlite3"
"path/filepath"
)
var dbPath string
func SetDbPath(path string) {
dbPath = path
}
func OpenDb(ctx context.Context, db string) (*sql.DB, error) {
db = filepath.Join(dbPath, db)
_, err := os.OpenFile(db, os.O_RDWR, 0600)
if err != nil {
return nil, err
}
return sql.Open("sqlite3", "file:"+db+"?_foreign_keys=true")
}
I traced down the problem to this dependency:
_ "github.com/mattn/go-sqlite3"
If I comment this out then the test runs fine, otherwise it hangs.
Strangely go run works just fine. Google says go-sqlite3 takes time to compile but then why is go run working normally?