Code Monkey home page Code Monkey logo

integration-tests-example's Introduction

Integration Tests Example

This project showcases how Ardan Labs handles integration tests in regards to databases. The patterns and techniques used to write integration tests with a database can also be applied to other services.

This repository runs a simple list daemon (listd) that implements a REST API for lists and items in relation to lists. The daemon uses a postgres database to persist data.

For information regarding the listd API, see the apiary.apib located in ./cmd/listd/deploy/.

Table of Contents

Running

Dependencies

The only dependencies to run the services in this repository are:

  • docker
  • docker-compose

Environment Variables

The program looks for the following environment variables:

  • LIST_DAEMON_PORT: The port that the list daemon listens to/serves from (Default: 3000).
  • LIST_DB_USER: The postgres database username that gets used within the postgres connection string (Default: root).
  • LIST_DB_PASS: The postgres database password that gets used within the postgres connection string (Default: root).
  • LIST_DB_NAME: The postgres database name that gets used within the postgres connection string (Default: list).
  • LIST_DB_HOST: The postgres database host name that gets used within the postgres connection string (Default db).
  • LIST_DB_PORT: The postgres database port that gets used within the postgres connection string (Default: 5432).
  • LIST_READ_TIMEOUT: The time, in seconds, of the read timeout of any outgoing read requests made by the internal HTTP server (Default: 5).
  • LIST_WRITE_TIMEOUT: The time, in seconds, of the read timeout of any outgoing write requests made by the internal HTTP server (Default: 10).
  • LIST_SHUTDOWN_TIMEOUT: The time, in seconds, of the graceful shutdown timeout of the list daemon. This is the amount of time in between an attempted, non-forceful shutdown and the finishing of open requests and/or the shutdown of integrated services such as the database (Default: 5).

If the environment variable has a supplied default and none are set within the context of the host machine, then the default will be used.

To set any given environment variable, simply execute the following pattern, replacing [ENV_NAME] with the name of the environment variable and [ENV_VALUE] with the desired value of the environment variable: export [ENV_NAME]=[ENV_VALUE]. To unset any set environment variable, simply execute the following pattern, replacing [ENV_NAME] with the name of the environment variable: unset [ENV_NAME].

Make Rule

To run the services simply execute the following command:

make run

This will stop any containers defined by the compose file if already running and then rebuild the containers using the compose file. The list daemon (listd) will be available at localhost:3000 and the postgres instance will be available at localhost:5432.

Testing

Dependencies

The only dependencies to test the go code in this repository are:

  • docker
  • docker-compose

Make Rule

To test the go code in this repository simply execute the following command:

make test

This will build the containers in docker-compose.test.yml and run GO111MODULE=on go test -mod=vendor ./... against all testable go code in the repository.

integration-tests-example's People

Contributors

asankov avatar george-e-shaw-iv avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.