Writing custom plugin tests - plugin table is not visible from dao


Using kong 0.14.1
I’ve created plugin which has own database table.
I want to develop api tests for it.
Between tests I want to truncate plugin table, i’m doing it this way:


And when I execute I have such error:
./kong/dao/factory.lua:321: attempt to index a nil value

After some debugging I’ve found workaround here

I hack file this way:

function _M.new(kong_config, new_db)

ppp = {}
ppp[“my-plugin-id”] = “my-plugin-id”
local self = {
db_type = kong_config.database,
daos = {},
additional_tables = {},
kong_config = kong_config,
– plugin_names = kong_config.loaded_plugins or {}
plugin_names = ppp

And then it works. But how can I solve my problem without hacking kong files?

When I start kong, I add my-plugin, but seems this is not enough:

            database = strategy,
            nginx_conf = "spec/fixtures/custom_nginx.template",
            plugins = "bundled,my-plugin-id"


@ovazhnev try running your busted tests with KONG_TEST_CUSTOM_PLUGINS=my-plugin-id env var, or potentially KONG_TEST_PLUGINS=my-plugin-id environment var. I believe this is necessary for tests to run migrations on your custom daos.lua defined tables and for the dao to know about them in the context of the test environment / bootstrapping helper.

Thanks. It helped. But I also noticed such warning once:

019/03/18 12:22:03 [warn] the ‘custom_plugins’ configuration property is deprecated, use ‘plugins’ instead
Error: ./kong/cmd/start.lua:60: nginx: [warn] [lua] log.lua:63: log(): the ‘custom_plugins’ configuration property is deprecated, use ‘plugins’ instead

So I tried KONG_TEST_PLUGINS=my-plugin-id and it also works.
I suspect “KONG_TEST_PLUGINS” is preferred

Great. Yea I accidentally wrong KONG_TEST_CUSTOM_PLUGINS twice, but I meant for you to try the one without CUSTOM. Thanks for reading between the lines!