2016-06-23 08:09:56 +02:00
|
|
|
package bdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestColumnNames(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cols := []Column{
|
2016-08-08 09:46:06 +02:00
|
|
|
{Name: "one"},
|
|
|
|
{Name: "two"},
|
|
|
|
{Name: "three"},
|
2016-06-23 08:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
out := strings.Join(ColumnNames(cols), " ")
|
|
|
|
if out != "one two three" {
|
|
|
|
t.Error("output was wrong:", out)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-13 18:51:40 +02:00
|
|
|
func TestColumnDBTypes(t *testing.T) {
|
|
|
|
cols := []Column{
|
2016-08-08 09:46:06 +02:00
|
|
|
{Name: "test_one", DBType: "integer"},
|
|
|
|
{Name: "test_two", DBType: "interval"},
|
2016-07-13 18:51:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
res := ColumnDBTypes(cols)
|
|
|
|
if res["TestOne"] != "integer" {
|
|
|
|
t.Errorf(`Expected res["TestOne"]="integer", got: %s`, res["TestOne"])
|
|
|
|
}
|
|
|
|
if res["TestTwo"] != "interval" {
|
|
|
|
t.Errorf(`Expected res["TestOne"]="interval", got: %s`, res["TestOne"])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-23 08:09:56 +02:00
|
|
|
func TestFilterColumnsByDefault(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cols := []Column{
|
|
|
|
{Name: "col1", Default: ""},
|
|
|
|
{Name: "col2", Default: "things"},
|
|
|
|
{Name: "col3", Default: ""},
|
|
|
|
{Name: "col4", Default: "things2"},
|
|
|
|
}
|
|
|
|
|
2016-06-23 08:48:49 +02:00
|
|
|
res := FilterColumnsByDefault(false, cols)
|
2016-06-23 08:09:56 +02:00
|
|
|
if res[0].Name != `col1` {
|
|
|
|
t.Errorf("Invalid result: %#v", res)
|
|
|
|
}
|
|
|
|
if res[1].Name != `col3` {
|
|
|
|
t.Errorf("Invalid result: %#v", res)
|
|
|
|
}
|
|
|
|
|
2016-06-23 08:48:49 +02:00
|
|
|
res = FilterColumnsByDefault(true, cols)
|
2016-06-23 08:09:56 +02:00
|
|
|
if res[0].Name != `col2` {
|
|
|
|
t.Errorf("Invalid result: %#v", res)
|
|
|
|
}
|
|
|
|
if res[1].Name != `col4` {
|
|
|
|
t.Errorf("Invalid result: %#v", res)
|
|
|
|
}
|
|
|
|
|
2016-06-23 08:48:49 +02:00
|
|
|
res = FilterColumnsByDefault(false, []Column{})
|
2016-06-23 08:09:56 +02:00
|
|
|
if res != nil {
|
|
|
|
t.Errorf("Invalid result: %#v", res)
|
|
|
|
}
|
|
|
|
}
|
2016-11-11 10:01:09 +01:00
|
|
|
|
|
|
|
func TestFilterColumnsByEnum(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cols := []Column{
|
|
|
|
{Name: "col1", DBType: "enum('hello')"},
|
|
|
|
{Name: "col2", DBType: "enum('hello','there')"},
|
|
|
|
{Name: "col3", DBType: "enum"},
|
|
|
|
{Name: "col4", DBType: ""},
|
|
|
|
{Name: "col5", DBType: "int"},
|
|
|
|
}
|
|
|
|
|
|
|
|
res := FilterColumnsByEnum(cols)
|
|
|
|
if res[0].Name != `col1` {
|
|
|
|
t.Errorf("Invalid result: %#v", res)
|
|
|
|
}
|
|
|
|
if res[1].Name != `col2` {
|
|
|
|
t.Errorf("Invalid result: %#v", res)
|
|
|
|
}
|
|
|
|
}
|