Testing Your Plugins
Before deploying a custom plugin to production, it is essential to validate its correctness, performance, and behavior under different conditions. TrustGate encourages writing unit tests and using mocks to simulate request/response contexts. Proper testing ensures that your plugin behaves as expected and doesn’t introduce regressions or performance issues.
Why Testing Matters
- ✅ Catch configuration or logic bugs early
- ✅ Ensure plugin behavior across multiple request scenarios
- ✅ Validate rejection, continuation, or halting logic
- ✅ Prevent regressions during future changes
- ✅ Gain confidence before shipping your plugin
Project Structure for Plugin Tests
Place your tests alongside your plugin inside the pkg/plugins/<your_plugin>/
folder.
What to Test
Here are key areas to focus on when testing your plugin:
-
✅ Configuration Validation Ensure your plugin handles missing or invalid configuration properly using
ValidateConfig()
. -
✅ Correct Behavior per Stage Test how the plugin behaves when executed at each stage (
pre_request
,post_request
, etc.). -
✅ Edge Cases Simulate missing headers, empty bodies, or malformed inputs and ensure your plugin responds appropriately.
-
✅ Error Handling Confirm that errors are returned clearly and that the plugin fails gracefully.
-
✅ Custom Settings Use a variety of
settings
inputs to test conditional logic or behavior toggles in your plugin.
Example: Using the Plugin in Gateway Configuration
Once your custom plugin is tested and registered, you can activate it in the gateway configuration with a curl
command like the following: