snippet/test/sqlite_test.go

51 lines
745 B
Go

package test
import (
"fmt"
"math/rand"
"testing"
"github.com/stretchr/testify/assert"
"myschools.me/suguo/snippet/sqlite"
)
type ABC struct {
A string
B string
C string
}
type CBA struct {
D string
E string
F string
}
func TestSqlite(t *testing.T) {
conf := &sqlite.Config{
DBFile: "tmp/abc.db",
}
if err := sqlite.Init(conf); err != nil {
assert.Nil(t, err)
}
db, err := sqlite.New()
assert.Nil(t, err)
assert.NotNil(t, db)
if err := sqlite.Migrate(&ABC{}, &CBA{}); err != nil {
assert.Nil(t, err)
}
}
func BenchmarkSqlite(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
m := rand.Intn(100) + 1
n := rand.Intn(m)
for i := 0; i < n; i++ {
fmt.Printf("%d", i)
}
}
})
}