Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.
/ api-gateway-demo Public archive

Nginx application showcasing how to do lightweight tests with ruby rspec

Notifications You must be signed in to change notification settings

meltwater/api-gateway-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API GATEWAY DEMO

This is an example of how to set up a test environment for an Nginx gateway, with tests implemented using Ruby Rspec.

Please read our blog posts Lightweight Tests for your Nginx API Gateway to understand the details of our testing approach.

Prerequisites

Project structure explained

├── nginx (Gateway configuration)
│   ├── conf.d
│   │   └── api-gateway.conf (Location directives)
│   ├── dns.conf (DNS resolver)
│   └── nginx.conf (Main config)
└── tests
    ├── hosts
    │   └── hosts (DNS resolutions for internal services)
    ├── nginx
    │   ├── conf.d
    │   │   └── services.conf (Internal services mock)
    │   └── dns.conf (Test DNS resolver)

Setting up the test docker container required 4 extra steps on top of the target Nginx setup:

  • Install and run dnsmasq (Step 1)
  • Override /etc/hosts file with DNS names for our internal services (Step 2)
  • Override production DNS resolver and inject virtual server configuration mocking internal services (Step 3)
  • Include self signed ssl certificate used in internal services mock (Step 4)
# Production config
COPY nginx/*                        /etc/nginx/
COPY nginx/conf.d/*                 /etc/nginx/conf.d/

# Test setup

# Step 1
RUN apt-get update; apt-get install dnsmasq -y

# Step 2 - we can not directly copy it to /etc/hosts since docker will
# regenerate the file and overwrite our changes. We will copy content from
# /etc/test.hosts to /etc/hosts on runtime in launch.sh script
COPY tests/hosts/hosts                /etc/test.hosts

# Step 3
COPY tests/nginx                      /etc/nginx/

# Step 4
COPY tests/ssl/nginx-selfsigned.crt   /etc/ssl/certs/nginx-selfsigned.crt
COPY tests/ssl/nginx-selfsigned.key   /etc/ssl/private/nginx-selfsigned.key

Run tests

Set up testing environment:

$ make compose-up-test

Execute tests:

$ make test

About

Nginx application showcasing how to do lightweight tests with ruby rspec

Topics

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published