Enabling plugins in test helpers


#1

Hi,

I have been writing tests for a couple plugins that I have written. I had a bit of trouble getting out of the starting gates as I initially missed the point that one needs to specify the plugins that should be enabled when calling start_kong - e.g. helpers.start_kong( { plugins = "bundled,my-plugin" }). After reading through the helpers code I noticed that if no plugins are specified then a default set are applied. Is there a particular reason this was done in this way? IMO, this seems to go against POLA as I would have expected the default to have been the standard set loaded via the plugins declaration in the tests config file and that this option would allow that to be overridden.

As it currently works, the plugin you are looking to test currently needs to be enabled in both locations or the tests won’t work. If the plugin is not in the test config one receives an error like schema violation (name: plugin 'my-plugin' not enabled; add it to the 'plugins' configuration property) when trying to insert the plugin to the db in the first place. Then, you also need to enable it when calling start_kong or you receive the error Error: ./kong/cmd/start.lua:50: nginx: [error] init_by_lua error: /kong/kong/init.lua:291: my-plugin plugin is in use but not enabled.

From the simple testing I’ve done, it seems like commenting out lines 1126-1130 in helpers.lua removes the requirement to enable the plugin when calling start_kong. That said, I can see value in allowing an override (to be able to test specific cases where only a subset of plugins are enabled) so perhaps this should be changed to override the configured plugins if provided rather than overriding to default if not provided? I was considering submitting a PR to this effect but thought perhaps I would raise the question here to discuss with others and see if there was a specific reason it was implemented this way in the first place?