Integration tests with Postgres
Launching a PostgreSQL service container
In this example, we will see a NodeJS project that is using PostgreSQL for data storage. For the integration test phase we will launch an instance of PostgreSQL in order to run a simple integration test.
The integration tests look for a PostgreSQL connection at
Example NodeJS project
You can see the example project at https://github.com/codefreshdemo/example_nodejs_postgres. The repository contains the NodeJS source code and the simple integration test.
You can play with it locally by using Docker compose to launch both the application and the PostgreSQL Database.
Create a pipeline with PostgreSQL integration tests
Here is the whole pipeline:
This pipeline does the following:
- Clones the source code through a Git clone step.
- Runs the tests while launching a service container for an active PostgreSQL instance passing the required environment variables (that match what the test is expecting).
Notice that both the DB as well as the tests share a set of variables (
POSTGRES_PASSWORD etc.) and thus we use YAML anchors to avoid duplication.
Notice that we also use the
readiness property in the testing phase so that we can verify PostgreSQL is ready and listening, before running the tests.
CI pipeline examples
Integration test example
Integration tests with MySQL
Integration tests with Redis
Integration tests with Mongo
Preload a DB with test data