Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
tests(*) simple refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
locao committed Jun 10, 2021
1 parent 4df9b89 commit 0c508ec
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
27 changes: 27 additions & 0 deletions t/00-sanity.t
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
66 changes: 66 additions & 0 deletions t/01-phases.t
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
File renamed without changes.

0 comments on commit 0c508ec

Please sign in to comment.