Plugins - Testing and build workflows


I am currently writing a number of plugins (bundles) in Python. Is there any recommended work flows to speed up development and testing.

My current flow is:

  1. Write some code blind (middlewares)
  2. Bundle up the middlewares
  3. Add bundle to bundle server
  4. Hot reload the gateway
  5. Test the middleware
  6. Oh, typo
  7. Fix typo
  8. Back to step 2.

All of the above doing within a local docker compose set up.

Because of the external dependencies such as tyk.decorators and gateway it seems like it is impossible to write the middlewares in isolation.

The best way that I can think of to handle this is to mock the Tyk dependencies and arguments passed in by the decorator i.e. request, session, metadata, spec etc and build my plugins using TDD.

TDD actually feels like best way to build in isolation but I don’t really like mocking code that I do not own.

Has anyone come up with a good workflow to build and test plugins?

I took a look at the available Tyk plugins such as Bot Detection and Loggly Logging as I was hoping they may have some tests.

I think being able to test middlewares is incredibly important as a simple mistake could take down an API.

Hopefully I am just missing something and all this is documented somewhere or my workflow is just completely wrong. :grin:


1 Like

(This has sparked a bit of an internal discussion here at tyk between the engineering team, so we haven’t disregarded this post, just no good answers yet!)

Not problem @Martin!

I’m going to continue mocking the imports and args for now although like I said, I really don’t like mocking code I don’t own.

I was thinking some test utils which could be installed via the supported languages (Js, Lua, Python, Ruby) dependency manager could be a good idea?

Look forward to hearing what the team comes up with. :smiley: