1
0
forked from MTSR/mapserver
mapserver/settings/settings_test.go

88 lines
1.3 KiB
Go
Raw Normal View History

2019-02-07 11:02:15 +03:00
package settings
import (
2019-02-08 18:02:24 +03:00
"io/ioutil"
"mapserver/mapobjectdb/sqlite"
"os"
"testing"
2019-02-07 11:02:15 +03:00
)
2019-02-08 18:02:24 +03:00
func TestStrings(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "TileDBTest.*.sqlite")
2019-02-07 11:02:15 +03:00
if err != nil {
panic(err)
}
defer os.Remove(tmpfile.Name())
2019-02-08 18:02:24 +03:00
db, err := sqlite.New(tmpfile.Name())
if err != nil {
panic(err)
}
2019-02-07 11:02:15 +03:00
2019-02-08 18:02:24 +03:00
err = db.Migrate()
if err != nil {
panic(err)
}
2019-02-07 11:02:15 +03:00
2019-02-08 18:02:24 +03:00
s := New(db)
2019-02-07 11:11:11 +03:00
2019-02-08 18:02:24 +03:00
//string
2019-02-07 11:11:11 +03:00
2019-02-08 18:02:24 +03:00
s.SetString("k", "v")
str := s.GetString("k", "v2")
if str != "v" {
t.Fatal("getstring failed: " + str)
}
2019-02-07 11:02:15 +03:00
2019-02-08 18:02:24 +03:00
if s.GetString("k2", "v3") != "v3" {
t.Fatal("getstring with default failed")
}
2019-02-07 11:02:15 +03:00
2019-02-08 18:02:24 +03:00
//int
2019-02-07 11:11:11 +03:00
2019-02-08 18:02:24 +03:00
s.SetInt("i", 123)
i := s.GetInt("i", 456)
if i != 123 {
t.Fatal("getint failed")
}
2019-02-07 11:02:15 +03:00
2019-02-08 18:02:24 +03:00
s.SetInt("i3", -123)
i = s.GetInt("i3", 456)
if i != -123 {
t.Fatal("getint negative failed")
}
2019-02-08 10:11:06 +03:00
2019-02-08 18:02:24 +03:00
if s.GetInt("i2", 111) != 111 {
t.Fatal("getint with default failed")
}
2019-02-07 11:02:15 +03:00
2019-02-08 18:02:24 +03:00
//int64
2019-02-07 11:11:11 +03:00
2019-02-08 18:02:24 +03:00
s.SetInt64("i", 1230000012300056)
i2 := s.GetInt64("i", 456)
if i2 != 1230000012300056 {
t.Fatal("getint64 failed")
}
2019-02-07 11:02:15 +03:00
2019-02-08 18:02:24 +03:00
if s.GetInt64("i2", 12300000123000564) != 12300000123000564 {
t.Fatal("getint with default failed")
}
2019-02-07 11:02:15 +03:00
2019-02-08 18:02:24 +03:00
//bool
2019-02-07 11:11:11 +03:00
2019-02-08 18:02:24 +03:00
s.SetBool("b", false)
b2 := s.GetBool("b", true)
if b2 {
t.Fatal("getbool failed")
}
2019-02-07 11:11:11 +03:00
2019-02-08 18:02:24 +03:00
if s.GetBool("b2", false) {
t.Fatal("getbool with default failed")
}
2019-02-07 11:11:11 +03:00
2019-02-08 18:02:24 +03:00
if !s.GetBool("b2", true) {
t.Fatal("getbool with default failed")
}
2019-02-07 11:11:11 +03:00
2019-02-07 11:02:15 +03:00
}