forked from golang-migrate/migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
115 lines (103 loc) · 2.31 KB
/
util_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package migrate
import (
"errors"
nurl "net/url"
"testing"
)
func TestSuintPanicsWithNegativeInput(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Fatal("expected suint to panic for -1")
}
}()
suint(-1)
}
func TestSuint(t *testing.T) {
if u := suint(0); u != 0 {
t.Fatalf("expected 0, got %v", u)
}
}
func TestFilterCustomQuery(t *testing.T) {
n, err := nurl.Parse("foo://host?a=b&x-custom=foo&c=d")
if err != nil {
t.Fatal(err)
}
nx := FilterCustomQuery(n).Query()
if nx.Get("x-custom") != "" {
t.Fatalf("didn't expect x-custom")
}
}
func TestSourceSchemeFromUrlSuccess(t *testing.T) {
urlStr := "protocol://path"
expected := "protocol"
u, err := sourceSchemeFromUrl(urlStr)
if err != nil {
t.Fatalf("expected no error, but received %q", err)
}
if u != expected {
t.Fatalf("expected %q, but received %q", expected, u)
}
}
func TestSourceSchemeFromUrlFailure(t *testing.T) {
cases := []struct {
name string
urlStr string
expectErr error
}{
{
name: "Empty",
urlStr: "",
expectErr: errors.New("source: URL cannot be empty"),
},
{
name: "NoScheme",
urlStr: "hello",
expectErr: errors.New("source: no scheme"),
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
_, err := sourceSchemeFromUrl(tc.urlStr)
if err.Error() != tc.expectErr.Error() {
t.Fatalf("expected %q, but received %q", tc.expectErr, err)
}
})
}
}
func TestDatabaseSchemeFromUrlSuccess(t *testing.T) {
urlStr := "protocol://path"
expected := "protocol"
u, err := databaseSchemeFromUrl(urlStr)
if err != nil {
t.Fatalf("expected no error, but received %q", err)
}
if u != expected {
t.Fatalf("expected %q, but received %q", expected, u)
}
}
func TestDatabaseSchemeFromUrlFailure(t *testing.T) {
cases := []struct {
name string
urlStr string
expectErr error
}{
{
name: "Empty",
urlStr: "",
expectErr: errors.New("database: URL cannot be empty"),
},
{
name: "NoScheme",
urlStr: "hello",
expectErr: errors.New("database: no scheme"),
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
_, err := databaseSchemeFromUrl(tc.urlStr)
if err.Error() != tc.expectErr.Error() {
t.Fatalf("expected %q, but received %q", tc.expectErr, err)
}
})
}
}