mysqlite/query_test.go
Sebastiaan de Schaetzen d48a828d2a
Some checks failed
Build / build (push) Failing after 14s
Possible first version
2025-02-18 12:53:51 +01:00

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")
}