mapserver/server/db/sqlite/sqlite_test.go
2019-02-05 13:13:34 +01:00

105 lines
1.7 KiB
Go

package sqlite
import (
_ "github.com/mattn/go-sqlite3"
"io/ioutil"
"mapserver/coords"
"mapserver/testutils"
"os"
"testing"
)
func TestMigrateEmpty(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "TestMigrateEmpty.*.sqlite")
if err != nil {
panic(err)
}
defer os.Remove(tmpfile.Name())
testutils.CreateEmptyDatabase(tmpfile.Name())
a, err := New(tmpfile.Name())
if err != nil {
panic(err)
}
err = a.Migrate()
if err != nil {
panic(err)
}
}
func TestMigrate(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "TestMigrate.*.sqlite")
if err != nil {
panic(err)
}
defer os.Remove(tmpfile.Name())
testutils.CreateEmptyDatabase(tmpfile.Name())
a, err := New(tmpfile.Name())
if err != nil {
panic(err)
}
err = a.Migrate()
if err != nil {
panic(err)
}
}
func TestMigrateAndQuery(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "TestMigrateAndQuery.*.sqlite")
if err != nil {
panic(err)
}
defer os.Remove(tmpfile.Name())
testutils.CreateTestDatabase(tmpfile.Name())
a, err := New(tmpfile.Name())
if err != nil {
panic(err)
}
err = a.Migrate()
if err != nil {
panic(err)
}
block, err := a.GetBlock(coords.NewMapBlockCoords(0, 0, 0))
if err != nil {
panic(err)
}
if block == nil {
t.Fatal("no data")
}
}
func TestMigrateAndQueryCount(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "TestMigrateAndQueryStride.*.sqlite")
if err != nil {
panic(err)
}
defer os.Remove(tmpfile.Name())
testutils.CreateTestDatabase(tmpfile.Name())
a, err := New(tmpfile.Name())
if err != nil {
panic(err)
}
err = a.Migrate()
if err != nil {
panic(err)
}
count, err := a.CountBlocks(0, 0)
if err != nil {
panic(err)
}
if count <= 0 {
t.Fatal("zero count")
}
}