mapserver/db/sqlite/sqlite_test.go
Buckaroo Banzai ddb5267a3b
Go releaser (#238)
* add goreleaser config

* update go.mod / gitignore

* dev/cross cleanup

* switch to cgo-less sqlite driver

* workflows

* fix build workflow

Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2022-02-01 14:59:29 +01:00

134 lines
2.2 KiB
Go

package sqlite
import (
"io/ioutil"
"mapserver/coords"
"mapserver/testutils"
"os"
"testing"
_ "modernc.org/sqlite"
)
func TestMigrateEmpty(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "TestMigrateEmpty.*.sqlite")
if err != nil {
panic(err)
}
defer os.Remove(tmpfile.Name())
testutils.CreateEmptyDatabase(tmpfile.Name())
a, err := New(tmpfile.Name())
if err != nil {
panic(err)
}
err = a.Migrate()
if err != nil {
panic(err)
}
}
func TestMigrate(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "TestMigrate.*.sqlite")
if err != nil {
panic(err)
}
defer os.Remove(tmpfile.Name())
testutils.CreateEmptyDatabase(tmpfile.Name())
a, err := New(tmpfile.Name())
if err != nil {
panic(err)
}
err = a.Migrate()
if err != nil {
panic(err)
}
}
func TestMigrateAndQuery(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "TestMigrateAndQuery.*.sqlite")
if err != nil {
panic(err)
}
defer os.Remove(tmpfile.Name())
testutils.CreateTestDatabase(tmpfile.Name())
a, err := New(tmpfile.Name())
if err != nil {
panic(err)
}
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")
}
}
func TestMigrateAndQueryCount(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 := New(tmpfile.Name())
if err != nil {
panic(err)
}
err = a.Migrate()
if err != nil {
panic(err)
}
count, err := a.CountBlocks()
if err != nil {
panic(err)
}
if count <= 0 {
t.Fatal("zero count")
}
}
func TestMigrateAndQueryTimestamp(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 := New(tmpfile.Name())
if err != nil {
panic(err)
}
err = a.Migrate()
if err != nil {
panic(err)
}
count, err := a.GetTimestamp()
if err != nil {
panic(err)
}
if count <= 0 {
t.Fatal("zero count")
}
}