-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqlutil_test.go
93 lines (87 loc) · 1.8 KB
/
sqlutil_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
89
90
91
92
93
package sqlutil_test
import (
"testing"
"github.com/madhab452/csvtosql/cmd/sqlutil"
)
func TestToColumnName(t *testing.T) {
tests := []struct {
description string
wantError error
given string
want string
}{
{
description: "Single space between words",
wantError: nil,
given: "test col",
want: "test_col",
},
{
description: "Double space between words",
wantError: nil,
given: "test col",
want: "test_col",
},
{
description: "Single char.",
wantError: nil,
given: "x",
want: "x",
},
{
description: "Empty value",
wantError: nil,
given: "",
want: "unknown_1",
},
{
description: "Empty value",
wantError: nil,
given: "",
want: "unknown_2",
},
{
description: "lots of unique characters",
wantError: nil,
given: "test*** ___'''***'''special col",
want: "test_special_col",
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
got := sqlutil.ToColumnName(tt.given)
if got != tt.want {
t.Errorf("unexpected, got: %v, want: %v", got, tt.want)
}
})
}
}
func TestToTableName(t *testing.T) {
tests := []struct {
description string
wantError error
given string
want string
}{
{
description: "",
wantError: nil,
given: "./csvs/BTC-USD-2.csv",
want: "btc_usd_2",
},
{
description: "",
wantError: nil,
given: "/Users/lorem/Downloads/Sample Test (test 101).csv",
want: "sample_test_test_101_",
},
}
for _, tt := range tests {
t.Run(tt.description, func(t *testing.T) {
got := sqlutil.ToTableName(tt.given)
if got != tt.want {
t.Errorf("unexpected, got: %v, want: %v", got, tt.want)
}
})
}
}