forked from go-gorm/postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrator_test.go
102 lines (100 loc) · 2.43 KB
/
migrator_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
package postgres
import "testing"
func Test_parseDefaultValueValue(t *testing.T) {
type args struct {
defaultValue string
}
tests := []struct {
name string
args args
want string
}{
{
name: "it should works with number without colons",
args: args{defaultValue: "0"},
want: "0",
},
{
name: "it should works with number and two colons",
args: args{defaultValue: "0::int8"},
want: "0",
},
{
name: "it should works with number and three colons",
args: args{defaultValue: "0:::int8"},
want: "0",
},
{
name: "it should works with empty string without colons",
args: args{defaultValue: "''"},
want: "",
},
{
name: "it should works with empty string with two colons",
args: args{defaultValue: "''::character varying"},
want: "",
},
{
name: "it should works with empty string with three colons",
args: args{defaultValue: "'':::character varying"},
want: "",
},
{
name: "it should works with string without colons",
args: args{defaultValue: "'field'"},
want: "field",
},
{
name: "it should works with string with two colons",
args: args{defaultValue: "'field'::character varying"},
want: "field",
},
{
name: "it should works with string with three colons",
args: args{defaultValue: "'field':::character varying"},
want: "field",
},
{
name: "it should works with value with two colons",
args: args{defaultValue: "field"},
want: "field",
},
{
name: "it should works with value without colons",
args: args{defaultValue: "field::character varying"},
want: "field",
},
{
name: "it should works with value with three colons",
args: args{defaultValue: "field:::character varying"},
want: "field",
},
{
name: "it should works with function without colons",
args: args{defaultValue: "now()"},
want: "now()",
},
{
name: "it should works with function with two colons",
args: args{defaultValue: "now()::timestamp without time zone"},
want: "now()",
},
{
name: "it should works with json without colons",
args: args{defaultValue: "{}"},
want: "{}",
},
{
name: "it should works with json with two colons",
args: args{defaultValue: "{}::jsonb"},
want: "{}",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := parseDefaultValueValue(tt.args.defaultValue); got != tt.want {
t.Errorf("parseDefaultValueValue() = %v, want %v", got, tt.want)
}
})
}
}