【发布时间】:2017-12-10 23:10:00
【问题描述】:
我刚开始学习 golang,不确定我的错误是概念上的还是语言上的。
这很奇怪,因为错误只发生在对我的代码进行单元测试时。如果我“跑步”一切正常。作为 sqlite 驱动程序,我使用 mattn/go-sqlite3。
这里是问题发生的地方:
func dbExec(command *string) {
db, err := sql.Open("sqlite3", dbPath) // Path and driver are set correcrtly
defer db.Close()
if err != nil { //No problem here
panic(err)
}
_, err = db.Exec(*command)
if err != nil { //Here the errorNo14 "Unable to open the database file" occurs
panic(err)
}
}
所以在我看来,可以找到数据库文件,但由于其他限制而无法打开。我的所有代码都没有并发。到目前为止,我只有一个测试方法,所以即使测试将同时进行,到目前为止也只有一个线程。也许有人有想法!问题似乎很基本,我的代码真的没有更多。
【问题讨论】:
标签: unit-testing go sqlite