Skip to content

Commit be6b7d1

Browse files
committed
Add test for DSN without trailing DB
Also make other tests more generic since error messages appear to have changed in more recent redis versions.
1 parent 7166523 commit be6b7d1

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

t/connector.t

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ location /t {
6464
assert(redis and not err,
6565
"try_hosts should return a connection and no error")
6666

67-
assert(previous_errors[1] == "connection refused",
68-
"previous_errors[1] should be 'connection refused'")
69-
assert(previous_errors[2] == "connection refused",
70-
"previous_errors[2] should be 'connection refused'")
67+
assert(string.len(previous_errors[1]) > 0,
68+
"previous_errors[1] should contain an error")
69+
assert(string.len(previous_errors[2]) > 0,
70+
"previous_errors[2] should contain an error")
7171

7272
assert(redis:set("dog", "an animal"),
7373
"redis connection should be working")
@@ -83,10 +83,10 @@ location /t {
8383
assert(not redis and err == "no hosts available",
8484
"no available hosts should return an error")
8585

86-
assert(previous_errors[1] == "connection refused",
87-
"previous_errors[1] should be 'connection refused'")
88-
assert(previous_errors[2] == "connection refused",
89-
"previous_errors[2] should be 'connection refused'")
86+
assert(string.len(previous_errors[1]) > 0,
87+
"previous_errors[1] should contain an error")
88+
assert(string.len(previous_errors[2]) > 0,
89+
"previous_errors[2] should contain an error")
9090
}
9191
}
9292
--- request
@@ -203,7 +203,7 @@ location /t {
203203
})
204204

205205
local redis, err = rc:connect()
206-
assert(not redis and string.find(err, "ERR Client sent AUTH, but no password is set"),
206+
assert(not redis and string.find(err, "ERR") and string.find(err, "AUTH"),
207207
"connect should fail with password error")
208208

209209
}
@@ -383,3 +383,28 @@ location /t {
383383
GET /t
384384
--- no_error_log
385385
[error]
386+
387+
388+
=== TEST 10: DSN without DB
389+
--- http_config eval: $::HttpConfig
390+
--- config
391+
location /t {
392+
lua_socket_log_errors Off;
393+
content_by_lua_block {
394+
local user_params = {
395+
url = "redis://foo.example:$TEST_NGINX_REDIS_PORT",
396+
host = "127.0.0.1",
397+
}
398+
399+
local rc, err = require("resty.redis.connector").new(user_params)
400+
assert(rc and not err, "new should return positively")
401+
402+
local redis, err = rc:connect()
403+
assert(redis and not err, "connect should return positively")
404+
assert(redis:set("cat", "dog") and redis:get("cat") == "dog")
405+
}
406+
}
407+
--- request
408+
GET /t
409+
--- no_error_log
410+
[error]

0 commit comments

Comments
 (0)