-
Notifications
You must be signed in to change notification settings - Fork 553
/
Copy pathcolumn_test.go
88 lines (74 loc) · 1.8 KB
/
column_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package drivers
import (
"strings"
"testing"
)
func TestColumnNames(t *testing.T) {
t.Parallel()
cols := []Column{
{Name: "one"},
{Name: "two"},
{Name: "three"},
}
out := strings.Join(ColumnNames(cols), " ")
if out != "one two three" {
t.Error("output was wrong:", out)
}
}
func TestColumnDBTypes(t *testing.T) {
cols := []Column{
{Name: "test_one", DBType: "integer"},
{Name: "test_two", DBType: "interval"},
}
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"])
}
}
func TestFilterColumnsByDefault(t *testing.T) {
t.Parallel()
cols := []Column{
{Name: "col1", Default: ""},
{Name: "col2", Default: "things"},
{Name: "col3", Default: ""},
{Name: "col4", Default: "things2"},
}
res := FilterColumnsByDefault(false, cols)
if res[0].Name != `col1` {
t.Errorf("Invalid result: %#v", res)
}
if res[1].Name != `col3` {
t.Errorf("Invalid result: %#v", res)
}
res = FilterColumnsByDefault(true, cols)
if res[0].Name != `col2` {
t.Errorf("Invalid result: %#v", res)
}
if res[1].Name != `col4` {
t.Errorf("Invalid result: %#v", res)
}
res = FilterColumnsByDefault(false, []Column{})
if res != nil {
t.Errorf("Invalid result: %#v", res)
}
}
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)
}
}