28 lines
723 B
Go
28 lines
723 B
Go
package mysqlite
|
|
|
|
import (
|
|
"github.com/stretchr/testify/require"
|
|
"testing"
|
|
)
|
|
|
|
func openTestDb(t *testing.T) *Db {
|
|
db := openEmptyTestDb(t)
|
|
db.Query("create table mytable (key text, value text)").MustExec()
|
|
db.Query("insert into mytable(key, value) values ('foo', 'bar')").MustExec()
|
|
return db
|
|
}
|
|
|
|
func TestSimpleQuery(t *testing.T) {
|
|
db := openTestDb(t)
|
|
var count int
|
|
db.Query("select count(*) from mytable").MustScanSingle(&count)
|
|
require.Equal(t, 1, count, "expected empty count")
|
|
}
|
|
|
|
func TestSimpleQueryWithArgs(t *testing.T) {
|
|
db := openTestDb(t)
|
|
var value string
|
|
db.Query("select value from mytable where key = ?").Bind("foo").MustScanSingle(&value)
|
|
require.Equal(t, "bar", value, "bad value returned")
|
|
}
|