This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
94 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use strict; | ||
use warnings FATAL => 'all'; | ||
use Test::Nginx::Socket::Lua; | ||
|
||
plan tests => 2; | ||
|
||
run_tests(); | ||
|
||
__DATA__ | ||
=== TEST 1: load lua-resty-dns-client | ||
--- config | ||
location = /t { | ||
access_by_lua_block { | ||
local client = require("resty.dns.client") | ||
assert(client.init()) | ||
local host = "localhost" | ||
local typ = client.TYPE_A | ||
local answers, err = assert(client.resolve(host, { qtype = typ })) | ||
ngx.say(answers[1].address) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
127.0.0.1 | ||
--- no_error_log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use Test::Nginx::Socket; | ||
|
||
plan tests => repeat_each() * (blocks() * 5); | ||
|
||
workers(6); | ||
|
||
no_shuffle(); | ||
run_tests(); | ||
|
||
__DATA__ | ||
=== TEST 1: client supports access phase | ||
--- config | ||
location = /t { | ||
access_by_lua_block { | ||
local client = require("resty.dns.client") | ||
assert(client.init()) | ||
local host = "localhost" | ||
local typ = client.TYPE_A | ||
local answers, err = client.resolve(host, { qtype = typ }) | ||
if not answers then | ||
ngx.say("failed to resolve: ", err) | ||
end | ||
ngx.say("address name: ", answers[1].name) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
address name: localhost | ||
--- no_error_log | ||
[error] | ||
dns lookup pool exceeded retries | ||
API disabled in the context of init_worker_by_lua | ||
=== TEST 2: client does not support init_worker phase | ||
--- http_config eval | ||
qq { | ||
init_worker_by_lua_block { | ||
local client = require("resty.dns.client") | ||
assert(client.init()) | ||
local host = "konghq.com" | ||
local typ = client.TYPE_A | ||
answers, err = client.resolve(host, { qtype = typ }) | ||
} | ||
} | ||
--- config | ||
location = /t { | ||
access_by_lua_block { | ||
ngx.say("answers: ", answers) | ||
ngx.say("err: ", err) | ||
} | ||
} | ||
--- request | ||
GET /t | ||
--- response_body | ||
answers: nil | ||
err: dns client error: 101 empty record received | ||
--- no_error_log | ||
[error] | ||
dns lookup pool exceeded retries | ||
API disabled in the context of init_worker_by_lua |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters