1
0
forked from MTSR/mapserver
mapserver/mapobjectdb/sqlite_test.go

66 lines
934 B
Go
Raw Normal View History

2019-01-21 17:13:33 +03:00
package mapobjectdb
2019-01-14 14:38:26 +03:00
import (
"io/ioutil"
2019-01-16 18:36:28 +03:00
"mapserver/coords"
2019-01-14 14:38:26 +03:00
"os"
"testing"
)
func TestMigrate(t *testing.T) {
2019-01-17 10:01:48 +03:00
tmpfile, err := ioutil.TempFile("", "TileDBTest.*.sqlite")
2019-01-14 14:38:26 +03:00
if err != nil {
panic(err)
}
defer os.Remove(tmpfile.Name())
db, err := NewSqliteAccessor(tmpfile.Name())
if err != nil {
panic(err)
}
err = db.Migrate()
if err != nil {
panic(err)
}
2019-01-14 14:48:46 +03:00
2019-01-17 10:53:07 +03:00
pos := coords.NewTileCoords(0, 0, 13, 0)
tile, err := db.GetTile(pos)
2019-01-14 14:48:46 +03:00
if err != nil {
panic(err)
}
2019-01-17 10:01:48 +03:00
if tile != nil {
t.Fatal("non-empty tile found")
}
data := []byte{0x01, 0x02}
2019-01-17 10:53:07 +03:00
tile2 := Tile{Pos: pos, Data: data}
2019-01-17 10:01:48 +03:00
err = db.SetTile(&tile2)
if err != nil {
panic(err)
}
2019-01-17 10:53:07 +03:00
tile3, err := db.GetTile(pos)
2019-01-17 10:01:48 +03:00
if err != nil {
panic(err)
}
if tile3 == nil {
t.Fatal("no data returned")
}
if len(tile2.Data) != len(tile3.Data) {
t.Fatal("inserted data does not match")
}
err = db.SetTile(&tile2)
2019-01-16 18:36:28 +03:00
if err != nil {
panic(err)
}
2019-01-14 14:48:46 +03:00
2019-01-14 14:38:26 +03:00
}