Skip to content

Commit 5e7accf

Browse files
committed
Added test for parse_dsn
1 parent 6a73aa5 commit 5e7accf

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

t/connector.t

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,54 @@ location /t {
231231
GET /t
232232
--- no_error_log
233233
[error]
234+
235+
236+
=== TEST 8: parse_dsn
237+
--- http_config eval: $::HttpConfig
238+
--- config
239+
location /t {
240+
lua_socket_log_errors Off;
241+
content_by_lua_block {
242+
local rc = require("resty.redis.connector")
243+
244+
local params = {
245+
url = "redis://[email protected]:$TEST_NGINX_REDIS_PORT/4"
246+
}
247+
248+
local ok, err = rc.parse_dsn(params)
249+
assert(ok and not err,
250+
"url should parse without error: " .. tostring(err))
251+
252+
assert(params.host == "127.0.0.1", "host should be localhost")
253+
assert(tonumber(params.port) == $TEST_NGINX_REDIS_PORT,
254+
"port should be $TEST_NGINX_REDIS_PORT")
255+
assert(tonumber(params.db) == 4, "db should be 4")
256+
assert(params.password == "foo", "password should be foo")
257+
258+
259+
local params = {
260+
url = "sentinel://foo@foomaster:s/2"
261+
}
262+
263+
local ok, err = rc.parse_dsn(params)
264+
assert(ok and not err,
265+
"url should parse without error: " .. tostring(err))
266+
267+
assert(params.master_name == "foomaster", "master_name should be foomaster")
268+
assert(params.role == "slave", "role should be slave")
269+
assert(tonumber(params.db) == 2, "db should be 2")
270+
271+
272+
local params = {
273+
url = "sentinels:/wrongformat",
274+
}
275+
276+
local ok, err = rc.parse_dsn(params)
277+
assert(not ok and err == "could not parse DSN: nil",
278+
"url should fail to parse")
279+
}
280+
}
281+
--- request
282+
GET /t
283+
--- no_error_log
284+
[error]

0 commit comments

Comments
 (0)