snippet/test/sqlite_test.go

51 lines
745 B
Go
Raw Permalink Normal View History

2021-09-03 08:44:20 +00:00
package test
import (
2021-09-04 03:03:51 +00:00
"fmt"
"math/rand"
2021-09-03 08:44:20 +00:00
"testing"
2022-04-14 14:12:57 +00:00
"github.com/stretchr/testify/assert"
2021-09-03 14:23:46 +00:00
"myschools.me/suguo/snippet/sqlite"
2021-09-03 08:44:20 +00:00
)
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{
2022-04-14 14:12:57 +00:00
DBFile: "tmp/abc.db",
2021-09-03 08:44:20 +00:00
}
if err := sqlite.Init(conf); err != nil {
2022-04-14 14:12:57 +00:00
assert.Nil(t, err)
2021-09-03 08:44:20 +00:00
}
db, err := sqlite.New()
2022-04-14 14:12:57 +00:00
assert.Nil(t, err)
assert.NotNil(t, db)
2021-09-03 08:44:20 +00:00
if err := sqlite.Migrate(&ABC{}, &CBA{}); err != nil {
2022-04-14 14:12:57 +00:00
assert.Nil(t, err)
2021-09-03 08:44:20 +00:00
}
}
2021-09-04 03:03:51 +00:00
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++ {
2021-09-15 14:53:03 +00:00
fmt.Printf("%d", i)
2021-09-04 03:03:51 +00:00
}
}
})
}