• Software
  • Cookbook
  • Software
  • Cookbook
  • Home
  • Rand
    • Minecraft Sucks
  • Docs
    • SPA Deployments in AWS
    • Minecraft Server Administration
    • Test Harness for Postgres Integrations
    • Enterprise REST API
  • Cookbook
    • Cookies
    • Muffins
    • Pasta

Test Harness for Postgres Integrations

Three-container solution for testing REST services against a Postgres database.

Why would you want this?

The purpose of a system is what it does. So it's nice to know that the application is affecting the database in its intended manner. We'll use containers because it's a convenient way to define these things in code, and most production scenarios will call for containerization as in-market test runners are typically Kubernetes wrappers.

Solution

We'll run a three-container test suite with Docker compose. Postgres will run as host alias database, our API as host alias api, and the Test Runner as host alias test. We'll explicitly define a network ensuring that all three containers are members, and use environment variables and the defined aliases to manage connections between them. We're assuming a Node ecosystem, so the Test Runner will be boilerplate jest, you should extend to suit your needs.

Prerequisites

  • A Docker account

Steps

Clone the repository.

Build $ docker compose build

Run $ docker compose up

This will run all three containers, in order. The test script calls the increment endpoint twice, and manually checks the data.

Prev
Minecraft Server Administration
Next
Enterprise REST API