2019-01-10 19:50:31 +03:00
|
|
|
package mapblockaccessor
|
|
|
|
|
|
|
|
import (
|
2019-01-13 18:37:03 +03:00
|
|
|
"github.com/sirupsen/logrus"
|
2019-01-10 19:50:31 +03:00
|
|
|
"io/ioutil"
|
|
|
|
"mapserver/coords"
|
2019-01-11 12:24:10 +03:00
|
|
|
"mapserver/db"
|
2019-01-13 18:37:03 +03:00
|
|
|
"mapserver/testutils"
|
|
|
|
"os"
|
|
|
|
"testing"
|
2019-01-10 19:50:31 +03:00
|
|
|
)
|
|
|
|
|
2019-01-11 12:24:10 +03:00
|
|
|
func TestSimpleAccess(t *testing.T) {
|
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
2019-01-10 19:50:31 +03:00
|
|
|
|
|
|
|
tmpfile, err := ioutil.TempFile("", "TestMigrate.*.sqlite")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-01-11 12:24:10 +03:00
|
|
|
defer os.Remove(tmpfile.Name())
|
|
|
|
testutils.CreateTestDatabase(tmpfile.Name())
|
2019-01-10 19:50:31 +03:00
|
|
|
|
|
|
|
a, err := db.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)
|
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|