kong - 测试kong自定义插件发生dns服务器错误:3名称错误
问题描述
在使用以下代码进行 kong 插件测试时,我遇到了 dns 服务器错误。测试用例做一个get请求很简单。上游服务是部署在内部 k8s 集群中的服务。我kong-vagrant
用来在我的 Windows 10 PC 上进行测试。
local helpers = require "spec.helpers"
local pl_pretty = require "pl.pretty"
local PLUGIN_NAME = "myplugin"
for _, strategy in helpers.each_strategy({"postgres"}) do
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "]", function()
local client
lazy_setup(function()
local bp = helpers.get_db_utils(strategy, nil, { PLUGIN_NAME })
local service = bp.services:insert {
name = "service-mockbin",
url = "http://pabc-doc.k8s.io:30283/docs/",
}
-- local service = bp.services:insert {
-- name = "service-mockbin",
-- url = "https://mockbin.com/request",
-- }
local route1 = bp.routes:insert({
paths = { "/docs" },
service = service
})
-- add the plugin to test to the route we created
bp.plugins:insert {
name = PLUGIN_NAME,
route = { id = route1.id },
config = {},
}
-- start kong
assert(helpers.start_kong({
-- set the strategy
database = strategy,
-- use the custom test template to create a local mock server
nginx_conf = "spec/fixtures/custom_nginx.template",
-- make sure our plugin gets loaded
plugins = "bundled," .. PLUGIN_NAME,
}))
end)
lazy_teardown(function()
helpers.stop_kong(nil, true)
end)
before_each(function()
client = helpers.proxy_client()
end)
after_each(function()
if client then client:close() end
end)
describe("request", function()
it("get login", function()
local r = client:get("/docs")
pl_pretty.dump(r)
assert.response(r).has.status(200)
end)
end)
end)
end
错误:
2020/06/23 12:27:49 [error] 4297#0: *2 [lua] balancer.lua:929: execute(): DNS resolution failed: dns server error: 3 name error. Tried: ["(short)pabc-doc.k8s.io:(na) - cache-miss","pabc-doc.k8s.io:33 - cache-hit/dns server error: 3 name error","pabc-doc.k8s.io:1 - cache-hit/dns server error: 3 name error","pabc-doc.k8s.io:5 - cache-hit/dns server error: 3 name error"], client: 127.0.0.1, server: kong, request: "GET /docs HTTP/1.1", host: "0.0.0.0:9000"
如果我启动一个kong服务并配置上游服务,然后通过浏览器访问它,它就可以工作。并将如下代码放入自定义插件中,即可获取ip
local ip, port, try_list = toip("pabc-doc.k8s.io", 30283, false)
那么在使用busted
.
解决方案
推荐阅读
- sql - SQL 连接数据并获取与 NULL 不匹配的行
- go - Terraform 提供者应该如何处理在服务器端应用的默认值?
- javascript - 使用 JavaScript 连接 2 个具有不同主键的 JSON 对象
- python - gridsearchcv 中的 refit 选项是否会重新选择功能?
- rabbitmq - 将微服务与事件同步 (RabbitMQ)
- arrays - 如何处理 BehaviorSubjects、Observables 中的嵌套数组/对象?
- java - 断言 - 内部调用问题
- laravel - 如何在 Laravel 5.6 中设计我的分页表单并对其进行控制?换句话说,如何使用 Paginator Instance Method?s
- sql-server - 为什么当 SQL Server 设置为强制加密时 SSMS 允许登录,并且 SSMS 登录选项中未选择“加密连接”选项
- jquery - 如何根据 JQuery 中的特定条件在循环内禁用 TextInputs?