mapserver/db/sqlite_test.go

78 lines
1.3 KiB
Go
Raw Normal View History

2019-01-08 18:33:49 +03:00
package db
import (
2019-01-10 19:50:31 +03:00
"io/ioutil"
"mapserver/coords"
"os"
"testing"
2019-01-11 12:24:10 +03:00
"mapserver/testutils"
2019-01-10 19:50:31 +03:00
_ "github.com/mattn/go-sqlite3"
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 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
}