@@ -40,6 +40,25 @@ func TestParseURL(t *testing.T) {
40
40
}, {
41
41
url : "redis://foo:bar@localhost:123" ,
42
42
o : & Options {Addr : "localhost:123" , Username : "foo" , Password : "bar" },
43
+ }, {
44
+ // multiple params
45
+ url : "redis://localhost:123/?db=2&read_timeout=2&pool_fifo=true" ,
46
+ o : & Options {Addr : "localhost:123" , DB : 2 , ReadTimeout : 2 * time .Second , PoolFIFO : true },
47
+ }, {
48
+ // special case handling for disabled timeouts
49
+ url : "redis://localhost:123/?db=2&idle_timeout=0" ,
50
+ o : & Options {Addr : "localhost:123" , DB : 2 , IdleTimeout : - 1 },
51
+ }, {
52
+ // negative values disable timeouts as well
53
+ url : "redis://localhost:123/?db=2&idle_timeout=-1" ,
54
+ o : & Options {Addr : "localhost:123" , DB : 2 , IdleTimeout : - 1 },
55
+ }, {
56
+ // absent timeout values will use defaults
57
+ url : "redis://localhost:123/?db=2&idle_timeout=" ,
58
+ o : & Options {Addr : "localhost:123" , DB : 2 , IdleTimeout : 0 },
59
+ }, {
60
+ url : "redis://localhost:123/?db=2&idle_timeout" , // missing "=" at the end
61
+ o : & Options {Addr : "localhost:123" , DB : 2 , IdleTimeout : 0 },
43
62
}, {
44
63
url : "unix:///tmp/redis.sock" ,
45
64
o : & Options {Addr : "/tmp/redis.sock" },
@@ -50,11 +69,30 @@ func TestParseURL(t *testing.T) {
50
69
url : "unix://foo:bar@/tmp/redis.sock?db=3" ,
51
70
o : & Options {Addr : "/tmp/redis.sock" , Username : "foo" , Password : "bar" , DB : 3 },
52
71
}, {
72
+ // invalid db format
53
73
url : "unix://foo:bar@/tmp/redis.sock?db=test" ,
54
74
err : errors .New (`redis: invalid database number: strconv.Atoi: parsing "test": invalid syntax` ),
75
+ }, {
76
+ // invalid int value
77
+ url : "redis://localhost/?pool_size=five" ,
78
+ err : errors .New (`redis: invalid pool_size number: strconv.Atoi: parsing "five": invalid syntax` ),
79
+ }, {
80
+ // invalid bool value
81
+ url : "redis://localhost/?pool_fifo=yes" ,
82
+ err : errors .New (`redis: invalid pool_fifo boolean: expected true/false/1/0 or an empty string, got "yes"` ),
83
+ }, {
84
+ // it returns first error
85
+ url : "redis://localhost/?db=foo&pool_size=five" ,
86
+ err : errors .New (`redis: invalid database number: strconv.Atoi: parsing "foo": invalid syntax` ),
55
87
}, {
56
88
url : "redis://localhost/?abc=123" ,
57
- err : errors .New ("redis: no options supported" ),
89
+ err : errors .New ("redis: unexpected option: abc" ),
90
+ }, {
91
+ url : "redis://foo@localhost/?username=bar" ,
92
+ err : errors .New ("redis: unexpected option: username" ),
93
+ }, {
94
+ url : "redis://localhost/?wrte_timout=10s&abc=123" ,
95
+ err : errors .New ("redis: unexpected option: abc, wrte_timout" ),
58
96
}, {
59
97
url : "http://google.com" ,
60
98
err : errors .New ("redis: invalid URL scheme: http" ),
@@ -98,7 +136,7 @@ func comprareOptions(t *testing.T, actual, expected *Options) {
98
136
t .Errorf ("got %q, want %q" , actual .Addr , expected .Addr )
99
137
}
100
138
if actual .DB != expected .DB {
101
- t .Errorf ("got %q, expected %q" , actual .DB , expected .DB )
139
+ t .Errorf ("DB: got %q, expected %q" , actual .DB , expected .DB )
102
140
}
103
141
if actual .TLSConfig == nil && expected .TLSConfig != nil {
104
142
t .Errorf ("got nil TLSConfig, expected a TLSConfig" )
@@ -107,10 +145,49 @@ func comprareOptions(t *testing.T, actual, expected *Options) {
107
145
t .Errorf ("got TLSConfig, expected no TLSConfig" )
108
146
}
109
147
if actual .Username != expected .Username {
110
- t .Errorf ("got %q, expected %q" , actual .Username , expected .Username )
148
+ t .Errorf ("Username: got %q, expected %q" , actual .Username , expected .Username )
111
149
}
112
150
if actual .Password != expected .Password {
113
- t .Errorf ("got %q, expected %q" , actual .Password , expected .Password )
151
+ t .Errorf ("Password: got %q, expected %q" , actual .Password , expected .Password )
152
+ }
153
+ if actual .MaxRetries != expected .MaxRetries {
154
+ t .Errorf ("MaxRetries: got %v, expected %v" , actual .MaxRetries , expected .MaxRetries )
155
+ }
156
+ if actual .MinRetryBackoff != expected .MinRetryBackoff {
157
+ t .Errorf ("MinRetryBackoff: got %v, expected %v" , actual .MinRetryBackoff , expected .MinRetryBackoff )
158
+ }
159
+ if actual .MaxRetryBackoff != expected .MaxRetryBackoff {
160
+ t .Errorf ("MaxRetryBackoff: got %v, expected %v" , actual .MaxRetryBackoff , expected .MaxRetryBackoff )
161
+ }
162
+ if actual .DialTimeout != expected .DialTimeout {
163
+ t .Errorf ("DialTimeout: got %v, expected %v" , actual .DialTimeout , expected .DialTimeout )
164
+ }
165
+ if actual .ReadTimeout != expected .ReadTimeout {
166
+ t .Errorf ("ReadTimeout: got %v, expected %v" , actual .ReadTimeout , expected .ReadTimeout )
167
+ }
168
+ if actual .WriteTimeout != expected .WriteTimeout {
169
+ t .Errorf ("WriteTimeout: got %v, expected %v" , actual .WriteTimeout , expected .WriteTimeout )
170
+ }
171
+ if actual .PoolFIFO != expected .PoolFIFO {
172
+ t .Errorf ("PoolFIFO: got %v, expected %v" , actual .PoolFIFO , expected .PoolFIFO )
173
+ }
174
+ if actual .PoolSize != expected .PoolSize {
175
+ t .Errorf ("PoolSize: got %v, expected %v" , actual .PoolSize , expected .PoolSize )
176
+ }
177
+ if actual .MinIdleConns != expected .MinIdleConns {
178
+ t .Errorf ("MinIdleConns: got %v, expected %v" , actual .MinIdleConns , expected .MinIdleConns )
179
+ }
180
+ if actual .MaxConnAge != expected .MaxConnAge {
181
+ t .Errorf ("MaxConnAge: got %v, expected %v" , actual .MaxConnAge , expected .MaxConnAge )
182
+ }
183
+ if actual .PoolTimeout != expected .PoolTimeout {
184
+ t .Errorf ("PoolTimeout: got %v, expected %v" , actual .PoolTimeout , expected .PoolTimeout )
185
+ }
186
+ if actual .IdleTimeout != expected .IdleTimeout {
187
+ t .Errorf ("IdleTimeout: got %v, expected %v" , actual .IdleTimeout , expected .IdleTimeout )
188
+ }
189
+ if actual .IdleCheckFrequency != expected .IdleCheckFrequency {
190
+ t .Errorf ("IdleCheckFrequency: got %v, expected %v" , actual .IdleCheckFrequency , expected .IdleCheckFrequency )
114
191
}
115
192
}
116
193
0 commit comments