You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my plugin test case, I try to use assert.response(r).has.body() to assert response baby, but an error occurred.
I want to test http_mock, so I don't appoint plugins for my route, and I use pongo run test case.
local helpers = require "spec.helpers"
local http_mock = require("spec.helpers.http_mock")
local PLUGIN_NAME = "my-plugin"
for _, strategy in helpers.all_strategies() do if strategy ~= "cassandra" then
describe(PLUGIN_NAME .. ": (access) [#" .. strategy .. "]", function()
local client
lazy_setup(function()
mock, mock_port = assert(http_mock.new(8000, {
["/"] = {
content = [[
ngx.header.content_type = "application/json"
ngx.say("hello world")
ngx.exit(200)
]],
}
}))
assert(mock:start())
local bp = helpers.get_db_utils(strategy == "off" and "postgres" or strategy, nil, { PLUGIN_NAME })
-- Inject a test route. No need to create a service, there is a default
-- service which will echo the request.
local service = bp.services:insert {
name = "sso",
host = helpers.mock_upstream_host,
port = 8000,
protocol = helpers.mock_upstream_protocol,
}
local route = bp.routes:insert({
service = service,
paths = {'/test'}
})
-- 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,
-- write & load declarative config, only if 'strategy=off'
declarative_config = strategy == "off" and helpers.make_yaml_file() or nil,
}))
end)
lazy_teardown(function()
helpers.stop_kong(nil, true)
if mock then
mock:stop()
end
end)
before_each(function()
client = helpers.proxy_client(nil, 8000, "localhost")
end)
after_each(function()
if client then client:close() end
end)
describe("request", function()
it("gets a 'hello-world' header", function()
local r = client:get("/request", {
headers = {
host = "test1.com"
}
})
-- validate that the request succeeded, response status 200
assert.response(r).has.status(200)
assert.response(r).has.body("hello world")
end)
end)
end)
end end
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In my plugin test case, I try to use assert.response(r).has.body() to assert response baby, but an error occurred.
I want to test http_mock, so I don't appoint plugins for my route, and I use pongo run test case.
When I run command pongo run
But in https://github.com/Kong/kong/blob/master/spec/helpers/http_mock.lua , demo code use assert.response(r).has.body("hello world").
Beta Was this translation helpful? Give feedback.
All reactions