PolySwarmPolySwarmPolySwarmPolySwarm
Go to PolySwarm
Home

Integration Testing Your Engine

Unit tests are great for validating individual parts, but sometimes you want to validate that it all works together. microengine-webhooks-py includes an easy integration test setup to send bounties and see the engine responses.

It uses docker-compose to coordinate standing up all the services. Take a look at docker/docker-compose.yaml.

If you have been following along so far as we've been building our ClamAV engine, you will notice this too is missing the necessary component to run with clamd. To add it, we can add a new clamav-daemon service into the docker-compose.yaml.

clamav-daemon:
  networks:
    - microengine-webhooks
  image: mkodockx/docker-clamav/
  ports: '3310:3310'

Then, we need to add the CLAMD environment variables to our Engine. Edit the worker service to add the missing CLAMD_HOST and CLAMD_PORT environment variables.

worker:
  environment:
    - CLAMD_HOST=clamav-daemon
    - CLAMD_PORT=3310

Now, let's run the dockerized Engine system. To do that, we go back to our Terminal and run docker-compose as follows:

(psvenv) $ docker-compose -f docker/docker-compose.yaml --build up

This will build the two docker images for the ClamAv engine. It will start up everything, including an integration testing server. The integration server is a minimal Flask app that sends test messages to the Engine. Test messages are triggered by requests to the integration server. Developers will want to test both /test/bounty and /test/ping endpoints. Calling /test/bounty will send a test bounty, just like an Engine would receive from a webhook call sent by the PolySwarm Marketplace. Calling /test/ping will send a test ping, much like the one PolySwarm will use to validate a running webhook when you test your webhook in the PolySwarm UI.

There are currently two bounties sent when a user hits /test/bounty. One is malicious (EICAR), and the other is benign. You can trigger a bounty by sending a post request to http://localhost:5000/test/bounty as follows:

(psvenv) $ curl -X POST http://localhost:5000/test/bounty

The integration server logs will show the result that was returned from the Engine.

Next Steps

We have an Engine that works locally in your development environment, so let's connect it to the PolySwarm Marketplace for live testing.

2024 © PolySwarm Pte. Ltd.