@@ -17,67 +17,74 @@ import (
17
17
"time"
18
18
)
19
19
20
- var testDSNs = []struct {
20
+ var testDSNs []struct {
21
21
in string
22
22
out * Config
23
- }{{
24
- "username:password@protocol(address)/dbname?param=value" ,
25
- & Config {User : "username" , Passwd : "password" , Net : "protocol" , Addr : "address" , DBName : "dbname" , Params : map [string ]string {"param" : "value" }, Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : defaultLogger , AllowNativePasswords : true , CheckConnLiveness : true },
26
- }, {
27
- "username:password@protocol(address)/dbname?param=value&columnsWithAlias=true" ,
28
- & Config {User : "username" , Passwd : "password" , Net : "protocol" , Addr : "address" , DBName : "dbname" , Params : map [string ]string {"param" : "value" }, Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : defaultLogger , AllowNativePasswords : true , CheckConnLiveness : true , ColumnsWithAlias : true },
29
- }, {
30
- "username:password@protocol(address)/dbname?param=value&columnsWithAlias=true&multiStatements=true" ,
31
- & Config {User : "username" , Passwd : "password" , Net : "protocol" , Addr : "address" , DBName : "dbname" , Params : map [string ]string {"param" : "value" }, Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : defaultLogger , AllowNativePasswords : true , CheckConnLiveness : true , ColumnsWithAlias : true , MultiStatements : true },
32
- }, {
33
- "user@unix(/path/to/socket)/dbname?charset=utf8" ,
34
- & Config {User : "user" , Net : "unix" , Addr : "/path/to/socket" , DBName : "dbname" , charsets : []string {"utf8" }, Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : defaultLogger , AllowNativePasswords : true , CheckConnLiveness : true },
35
- }, {
36
- "user:password@tcp(localhost:5555)/dbname?charset=utf8&tls=true" ,
37
- & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "localhost:5555" , DBName : "dbname" , charsets : []string {"utf8" }, Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : defaultLogger , AllowNativePasswords : true , CheckConnLiveness : true , TLSConfig : "true" },
38
- }, {
39
- "user:password@tcp(localhost:5555)/dbname?charset=utf8mb4,utf8&tls=skip-verify" ,
40
- & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "localhost:5555" , DBName : "dbname" , charsets : []string {"utf8mb4" , "utf8" }, Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : defaultLogger , AllowNativePasswords : true , CheckConnLiveness : true , TLSConfig : "skip-verify" },
41
- }, {
42
- "user:password@/dbname?loc=UTC&timeout=30s&readTimeout=1s&writeTimeout=1s&allowAllFiles=1&clientFoundRows=true&allowOldPasswords=TRUE&collation=utf8mb4_unicode_ci&maxAllowedPacket=16777216&tls=false&allowCleartextPasswords=true&parseTime=true&rejectReadOnly=true" ,
43
- & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Collation : "utf8mb4_unicode_ci" , Loc : time .UTC , TLSConfig : "false" , AllowCleartextPasswords : true , AllowNativePasswords : true , Timeout : 30 * time .Second , ReadTimeout : time .Second , WriteTimeout : time .Second , Logger : defaultLogger , AllowAllFiles : true , AllowOldPasswords : true , CheckConnLiveness : true , ClientFoundRows : true , MaxAllowedPacket : 16777216 , ParseTime : true , RejectReadOnly : true },
44
- }, {
45
- "user:password@/dbname?allowNativePasswords=false&checkConnLiveness=false&maxAllowedPacket=0&allowFallbackToPlaintext=true" ,
46
- & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Loc : time .UTC , MaxAllowedPacket : 0 , Logger : defaultLogger , AllowFallbackToPlaintext : true , AllowNativePasswords : false , CheckConnLiveness : false },
47
- }, {
48
- "user:p@ss(word)@tcp([de:ad:be:ef::ca:fe]:80)/dbname?loc=Local" ,
49
- & Config {User : "user" , Passwd : "p@ss(word)" , Net : "tcp" , Addr : "[de:ad:be:ef::ca:fe]:80" , DBName : "dbname" , Loc : time .Local , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : defaultLogger , AllowNativePasswords : true , CheckConnLiveness : true },
50
- }, {
51
- "/dbname" ,
52
- & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : defaultLogger , AllowNativePasswords : true , CheckConnLiveness : true },
53
- }, {
54
- "/dbname%2Fwithslash" ,
55
- & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname/withslash" , Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : defaultLogger , AllowNativePasswords : true , CheckConnLiveness : true },
56
- }, {
57
- "@/" ,
58
- & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : defaultLogger , AllowNativePasswords : true , CheckConnLiveness : true },
59
- }, {
60
- "/" ,
61
- & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : defaultLogger , AllowNativePasswords : true , CheckConnLiveness : true },
62
- }, {
63
- "" ,
64
- & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : defaultLogger , AllowNativePasswords : true , CheckConnLiveness : true },
65
- }, {
66
- "user:p@/ssword@/" ,
67
- & Config {User : "user" , Passwd : "p@/ssword" , Net : "tcp" , Addr : "127.0.0.1:3306" , Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : defaultLogger , AllowNativePasswords : true , CheckConnLiveness : true },
68
- }, {
69
- "unix/?arg=%2Fsome%2Fpath.ext" ,
70
- & Config {Net : "unix" , Addr : "/tmp/mysql.sock" , Params : map [string ]string {"arg" : "/some/path.ext" }, Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : defaultLogger , AllowNativePasswords : true , CheckConnLiveness : true },
71
- }, {
72
- "tcp(127.0.0.1)/dbname" ,
73
- & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : defaultLogger , AllowNativePasswords : true , CheckConnLiveness : true },
74
- }, {
75
- "tcp(de:ad:be:ef::ca:fe)/dbname" ,
76
- & Config {Net : "tcp" , Addr : "[de:ad:be:ef::ca:fe]:3306" , DBName : "dbname" , Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : defaultLogger , AllowNativePasswords : true , CheckConnLiveness : true },
77
- }, {
78
- "user:password@/dbname?loc=UTC&timeout=30s&parseTime=true&timeTruncate=1h" ,
79
- & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Loc : time .UTC , Timeout : 30 * time .Second , ParseTime : true , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : defaultLogger , AllowNativePasswords : true , CheckConnLiveness : true , timeTruncate : time .Hour },
80
- },
23
+ }
24
+
25
+ func init () {
26
+ testDSNs = []struct {
27
+ in string
28
+ out * Config
29
+ }{{
30
+ "username:password@protocol(address)/dbname?param=value" ,
31
+ & Config {User : "username" , Passwd : "password" , Net : "protocol" , Addr : "address" , DBName : "dbname" , Params : map [string ]string {"param" : "value" }, Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : getLogger (), AllowNativePasswords : true , CheckConnLiveness : true },
32
+ }, {
33
+ "username:password@protocol(address)/dbname?param=value&columnsWithAlias=true" ,
34
+ & Config {User : "username" , Passwd : "password" , Net : "protocol" , Addr : "address" , DBName : "dbname" , Params : map [string ]string {"param" : "value" }, Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : getLogger (), AllowNativePasswords : true , CheckConnLiveness : true , ColumnsWithAlias : true },
35
+ }, {
36
+ "username:password@protocol(address)/dbname?param=value&columnsWithAlias=true&multiStatements=true" ,
37
+ & Config {User : "username" , Passwd : "password" , Net : "protocol" , Addr : "address" , DBName : "dbname" , Params : map [string ]string {"param" : "value" }, Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : getLogger (), AllowNativePasswords : true , CheckConnLiveness : true , ColumnsWithAlias : true , MultiStatements : true },
38
+ }, {
39
+ "user@unix(/path/to/socket)/dbname?charset=utf8" ,
40
+ & Config {User : "user" , Net : "unix" , Addr : "/path/to/socket" , DBName : "dbname" , charsets : []string {"utf8" }, Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : getLogger (), AllowNativePasswords : true , CheckConnLiveness : true },
41
+ }, {
42
+ "user:password@tcp(localhost:5555)/dbname?charset=utf8&tls=true" ,
43
+ & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "localhost:5555" , DBName : "dbname" , charsets : []string {"utf8" }, Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : getLogger (), AllowNativePasswords : true , CheckConnLiveness : true , TLSConfig : "true" },
44
+ }, {
45
+ "user:password@tcp(localhost:5555)/dbname?charset=utf8mb4,utf8&tls=skip-verify" ,
46
+ & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "localhost:5555" , DBName : "dbname" , charsets : []string {"utf8mb4" , "utf8" }, Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : getLogger (), AllowNativePasswords : true , CheckConnLiveness : true , TLSConfig : "skip-verify" },
47
+ }, {
48
+ "user:password@/dbname?loc=UTC&timeout=30s&readTimeout=1s&writeTimeout=1s&allowAllFiles=1&clientFoundRows=true&allowOldPasswords=TRUE&collation=utf8mb4_unicode_ci&maxAllowedPacket=16777216&tls=false&allowCleartextPasswords=true&parseTime=true&rejectReadOnly=true" ,
49
+ & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Collation : "utf8mb4_unicode_ci" , Loc : time .UTC , TLSConfig : "false" , AllowCleartextPasswords : true , AllowNativePasswords : true , Timeout : 30 * time .Second , ReadTimeout : time .Second , WriteTimeout : time .Second , Logger : getLogger (), AllowAllFiles : true , AllowOldPasswords : true , CheckConnLiveness : true , ClientFoundRows : true , MaxAllowedPacket : 16777216 , ParseTime : true , RejectReadOnly : true },
50
+ }, {
51
+ "user:password@/dbname?allowNativePasswords=false&checkConnLiveness=false&maxAllowedPacket=0&allowFallbackToPlaintext=true" ,
52
+ & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Loc : time .UTC , MaxAllowedPacket : 0 , Logger : getLogger (), AllowFallbackToPlaintext : true , AllowNativePasswords : false , CheckConnLiveness : false },
53
+ }, {
54
+ "user:p@ss(word)@tcp([de:ad:be:ef::ca:fe]:80)/dbname?loc=Local" ,
55
+ & Config {User : "user" , Passwd : "p@ss(word)" , Net : "tcp" , Addr : "[de:ad:be:ef::ca:fe]:80" , DBName : "dbname" , Loc : time .Local , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : getLogger (), AllowNativePasswords : true , CheckConnLiveness : true },
56
+ }, {
57
+ "/dbname" ,
58
+ & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : getLogger (), AllowNativePasswords : true , CheckConnLiveness : true },
59
+ }, {
60
+ "/dbname%2Fwithslash" ,
61
+ & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname/withslash" , Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : getLogger (), AllowNativePasswords : true , CheckConnLiveness : true },
62
+ }, {
63
+ "@/" ,
64
+ & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : getLogger (), AllowNativePasswords : true , CheckConnLiveness : true },
65
+ }, {
66
+ "/" ,
67
+ & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : getLogger (), AllowNativePasswords : true , CheckConnLiveness : true },
68
+ }, {
69
+ "" ,
70
+ & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : getLogger (), AllowNativePasswords : true , CheckConnLiveness : true },
71
+ }, {
72
+ "user:p@/ssword@/" ,
73
+ & Config {User : "user" , Passwd : "p@/ssword" , Net : "tcp" , Addr : "127.0.0.1:3306" , Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : getLogger (), AllowNativePasswords : true , CheckConnLiveness : true },
74
+ }, {
75
+ "unix/?arg=%2Fsome%2Fpath.ext" ,
76
+ & Config {Net : "unix" , Addr : "/tmp/mysql.sock" , Params : map [string ]string {"arg" : "/some/path.ext" }, Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : getLogger (), AllowNativePasswords : true , CheckConnLiveness : true },
77
+ }, {
78
+ "tcp(127.0.0.1)/dbname" ,
79
+ & Config {Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : getLogger (), AllowNativePasswords : true , CheckConnLiveness : true },
80
+ }, {
81
+ "tcp(de:ad:be:ef::ca:fe)/dbname" ,
82
+ & Config {Net : "tcp" , Addr : "[de:ad:be:ef::ca:fe]:3306" , DBName : "dbname" , Loc : time .UTC , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : getLogger (), AllowNativePasswords : true , CheckConnLiveness : true },
83
+ }, {
84
+ "user:password@/dbname?loc=UTC&timeout=30s&parseTime=true&timeTruncate=1h" ,
85
+ & Config {User : "user" , Passwd : "password" , Net : "tcp" , Addr : "127.0.0.1:3306" , DBName : "dbname" , Loc : time .UTC , Timeout : 30 * time .Second , ParseTime : true , MaxAllowedPacket : defaultMaxAllowedPacket , Logger : getLogger (), AllowNativePasswords : true , CheckConnLiveness : true , timeTruncate : time .Hour },
86
+ },
87
+ }
81
88
}
82
89
83
90
func TestDSNParser (t * testing.T ) {
0 commit comments