mapserver/db/sqlite_test.go

108 lines
1.8 KiB
Go
Raw Normal View History

2019-01-08 18:33:49 +03:00
package db
import (
2019-01-13 18:37:03 +03:00
_ "github.com/mattn/go-sqlite3"
2019-01-10 19:50:31 +03:00
"io/ioutil"
"mapserver/coords"
2019-01-13 18:37:03 +03:00
"mapserver/testutils"
2019-01-10 19:50:31 +03:00
"os"
"testing"
2019-01-08 18:33:49 +03:00
)
2019-01-10 19:50:31 +03:00
func TestMigrateEmpty(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "TestMigrateEmpty.*.sqlite")
if err != nil {
panic(err)
}
defer os.Remove(tmpfile.Name())
2019-01-11 12:24:10 +03:00
testutils.CreateEmptyDatabase(tmpfile.Name())
2019-01-10 19:50:31 +03:00
a, err := NewSqliteAccessor(tmpfile.Name())
if err != nil {
panic(err)
}
err = a.Migrate()
if err != nil {
panic(err)
}
2019-01-08 18:33:49 +03:00
}
2019-01-09 11:56:36 +03:00
2019-01-10 19:50:31 +03:00
func TestMigrate(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "TestMigrate.*.sqlite")
if err != nil {
panic(err)
}
defer os.Remove(tmpfile.Name())
2019-01-11 12:24:10 +03:00
testutils.CreateEmptyDatabase(tmpfile.Name())
2019-01-10 19:50:31 +03:00
a, err := NewSqliteAccessor(tmpfile.Name())
if err != nil {
panic(err)
}
err = a.Migrate()
if err != nil {
panic(err)
}
2019-01-09 11:56:36 +03:00
}
2019-01-09 12:16:22 +03:00
2019-01-10 19:50:31 +03:00
func TestMigrateAndQuery(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "TestMigrateAndQuery.*.sqlite")
if err != nil {
panic(err)
}
defer os.Remove(tmpfile.Name())
2019-01-11 12:24:10 +03:00
testutils.CreateTestDatabase(tmpfile.Name())
2019-01-10 19:50:31 +03:00
a, err := NewSqliteAccessor(tmpfile.Name())
if err != nil {
panic(err)
}
2019-01-11 12:24:10 +03:00
2019-01-10 19:50:31 +03:00
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")
}
2019-01-09 12:16:22 +03:00
}
2019-01-17 16:42:02 +03:00
func TestMigrateAndQueryStride(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 := NewSqliteAccessor(tmpfile.Name())
if err != nil {
panic(err)
}
err = a.Migrate()
if err != nil {
panic(err)
}
blocks, err := a.GetBlocks(coords.NewMapBlockCoords(0, -1, 0), coords.NewMapBlockCoords(0, 10, 0))
if err != nil {
panic(err)
}
if blocks == nil {
t.Fatal("no data")
}
}