Integration tests with Redis
Launching a Redis service container
In this example, we will see a Python project that is using Redis for storing a web counter. For the integration test phase we will launch both the application and an instance of Redis in order to run a simple integration test.
The application will be launched with a hostname
web while Redis will be at
Example Python project
You can see the example project at https://github.com/codefreshdemo/example_python_redis. The repository contains the Python source code and a test script.
You can play with it locally by using Docker compose to launch both the application and the Redis datastore.
Create a pipeline with Redis integration tests
Here is the whole pipeline:
This pipeline does the following:
- Clones the source code through a Git clone step.
- Builds a Docker image with the application itself through a build step.
- Builds a helper image that contains
curlthat will be used for the integration tests.
- Runs the test script while launching two service containers (one for the app and one for Redis).
Notice that we also use the
readiness property in the testing phase so that we can verify that both the application
as well as Redis are up, before running the tests.
Integration test script
The integration test is very simple. It just uses
curl to hit the Python endpoint and
grep to check for a well known string.
Notice that we use the helper image both for running the test (because of
curl) and for testing the readiness (because of
nc). In a more complex application these could be two completely different images.