@@ -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,27 @@ 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://localhost/?wrte_timout=10s&abc=123" ,
92
+ err : errors .New ("redis: unexpected option: abc, wrte_timout" ),
58
93
}, {
59
94
url : "http://google.com" ,
60
95
err : errors .New ("redis: invalid URL scheme: http" ),
@@ -98,7 +133,7 @@ func comprareOptions(t *testing.T, actual, expected *Options) {
98
133
t .Errorf ("got %q, want %q" , actual .Addr , expected .Addr )
99
134
}
100
135
if actual .DB != expected .DB {
101
- t .Errorf ("got %q, expected %q" , actual .DB , expected .DB )
136
+ t .Errorf ("DB: got %q, expected %q" , actual .DB , expected .DB )
102
137
}
103
138
if actual .TLSConfig == nil && expected .TLSConfig != nil {
104
139
t .Errorf ("got nil TLSConfig, expected a TLSConfig" )
@@ -107,10 +142,49 @@ func comprareOptions(t *testing.T, actual, expected *Options) {
107
142
t .Errorf ("got TLSConfig, expected no TLSConfig" )
108
143
}
109
144
if actual .Username != expected .Username {
110
- t .Errorf ("got %q, expected %q" , actual .Username , expected .Username )
145
+ t .Errorf ("Username: got %q, expected %q" , actual .Username , expected .Username )
111
146
}
112
147
if actual .Password != expected .Password {
113
- t .Errorf ("got %q, expected %q" , actual .Password , expected .Password )
148
+ t .Errorf ("Password: got %q, expected %q" , actual .Password , expected .Password )
149
+ }
150
+ if actual .MaxRetries != expected .MaxRetries {
151
+ t .Errorf ("MaxRetries: got %v, expected %v" , actual .MaxRetries , expected .MaxRetries )
152
+ }
153
+ if actual .MinRetryBackoff != expected .MinRetryBackoff {
154
+ t .Errorf ("MinRetryBackoff: got %v, expected %v" , actual .MinRetryBackoff , expected .MinRetryBackoff )
155
+ }
156
+ if actual .MaxRetryBackoff != expected .MaxRetryBackoff {
157
+ t .Errorf ("MaxRetryBackoff: got %v, expected %v" , actual .MaxRetryBackoff , expected .MaxRetryBackoff )
158
+ }
159
+ if actual .DialTimeout != expected .DialTimeout {
160
+ t .Errorf ("DialTimeout: got %v, expected %v" , actual .DialTimeout , expected .DialTimeout )
161
+ }
162
+ if actual .ReadTimeout != expected .ReadTimeout {
163
+ t .Errorf ("ReadTimeout: got %v, expected %v" , actual .ReadTimeout , expected .ReadTimeout )
164
+ }
165
+ if actual .WriteTimeout != expected .WriteTimeout {
166
+ t .Errorf ("WriteTimeout: got %v, expected %v" , actual .WriteTimeout , expected .WriteTimeout )
167
+ }
168
+ if actual .PoolFIFO != expected .PoolFIFO {
169
+ t .Errorf ("PoolFIFO: got %v, expected %v" , actual .PoolFIFO , expected .PoolFIFO )
170
+ }
171
+ if actual .PoolSize != expected .PoolSize {
172
+ t .Errorf ("PoolSize: got %v, expected %v" , actual .PoolSize , expected .PoolSize )
173
+ }
174
+ if actual .MinIdleConns != expected .MinIdleConns {
175
+ t .Errorf ("MinIdleConns: got %v, expected %v" , actual .MinIdleConns , expected .MinIdleConns )
176
+ }
177
+ if actual .MaxConnAge != expected .MaxConnAge {
178
+ t .Errorf ("MaxConnAge: got %v, expected %v" , actual .MaxConnAge , expected .MaxConnAge )
179
+ }
180
+ if actual .PoolTimeout != expected .PoolTimeout {
181
+ t .Errorf ("PoolTimeout: got %v, expected %v" , actual .PoolTimeout , expected .PoolTimeout )
182
+ }
183
+ if actual .IdleTimeout != expected .IdleTimeout {
184
+ t .Errorf ("IdleTimeout: got %v, expected %v" , actual .IdleTimeout , expected .IdleTimeout )
185
+ }
186
+ if actual .IdleCheckFrequency != expected .IdleCheckFrequency {
187
+ t .Errorf ("IdleCheckFrequency: got %v, expected %v" , actual .IdleCheckFrequency , expected .IdleCheckFrequency )
114
188
}
115
189
}
116
190
0 commit comments