1
0
forked from MTSR/mapserver
mapserver/mapblockaccessor/mapblockaccessor_test.go

72 lines
1.1 KiB
Go
Raw Normal View History

2019-01-10 19:50:31 +03:00
package mapblockaccessor
import (
"io"
"io/ioutil"
"mapserver/coords"
"mapserver/db"
"os"
"testing"
2019-01-11 10:58:12 +03:00
"github.com/sirupsen/logrus"
2019-01-10 19:50:31 +03:00
)
func copy(src, dst string) error {
in, err := os.Open(src)
if err != nil {
return err
}
defer in.Close()
out, err := os.Create(dst)
if err != nil {
return err
}
defer out.Close()
_, err = io.Copy(out, in)
if err != nil {
return err
}
return out.Close()
}
const testDatabase = "./testdata/map.sqlite"
func createTestDatabase(filename string) error {
return copy(testDatabase, filename)
}
func GetTestDatabase() db.DBAccessor {
tmpfile, err := ioutil.TempFile("", "TestMigrate.*.sqlite")
if err != nil {
panic(err)
}
createTestDatabase(tmpfile.Name())
a, err := db.NewSqliteAccessor(tmpfile.Name())
if err != nil {
panic(err)
}
err = a.Migrate()
if err != nil {
panic(err)
}
return a
}
func TestSimpleAccess(t *testing.T) {
2019-01-11 10:58:12 +03:00
logrus.SetLevel(logrus.DebugLevel)
2019-01-10 19:50:31 +03:00
a := GetTestDatabase()
cache := NewMapBlockAccessor(a)
mb, err := cache.GetMapBlock(coords.NewMapBlockCoords(0, 0, 0))
if err != nil {
panic(err)
}
if mb == nil {
t.Fatal("Mapblock is nil")
}
}