Add e2e and interface testing
Use catcher, newman and tavern
This commit is contained in:
parent
aebe3c3300
commit
ae0e57ec07
|
@ -9,4 +9,4 @@ notification-domain/
|
|||
TODO.txt
|
||||
deploy.sh
|
||||
coverage/
|
||||
test.sh
|
||||
local-test.sh
|
|
@ -8,7 +8,7 @@ repos:
|
|||
- id: check-merge-conflict
|
||||
- id: check-symlinks
|
||||
- id: check-yaml
|
||||
exclude: observability/
|
||||
exclude: (observability|testing/tavern)
|
||||
- id: debug-statements
|
||||
exclude: tests/
|
||||
- id: destroyed-symlinks
|
||||
|
@ -30,4 +30,12 @@ repos:
|
|||
rev: 5.12.0
|
||||
hooks:
|
||||
- id: isort
|
||||
args: ['--profile', 'black', '--src-path', 'flights-domain/flights-information/src', 'auth-domain/user-manager/src', 'gateway/src', 'subscription-domain/subscription-manager/src']
|
||||
args: [
|
||||
'--profile',
|
||||
'black',
|
||||
'--src-path',
|
||||
'flights-domain/flights-information/src',
|
||||
'auth-domain/user-manager/src',
|
||||
'gateway/src',
|
||||
'subscription-domain/subscription-manager/src'
|
||||
]
|
||||
|
|
16
run.sh
16
run.sh
|
@ -98,6 +98,7 @@ elif [ -n "$domain" ] && [ -z "$down" ]; then
|
|||
export API_IMAGE=$USER/user-manager:test
|
||||
docker compose -f auth-domain/docker-compose.dev.yml --env-file auth-domain/.env.dev down
|
||||
if [ -n "$integration" ]; then
|
||||
export TEST_TARGET=INTEGRATION
|
||||
docker compose -f auth-domain/docker-compose.dev.yml --env-file auth-domain/.env.dev up -d
|
||||
docker compose -f auth-domain/docker-compose.dev.yml --env-file auth-domain/.env.dev exec auth-api python manage.py recreate_db
|
||||
docker compose -f auth-domain/docker-compose.dev.yml --env-file auth-domain/.env.dev exec auth-api python manage.py seed_db
|
||||
|
@ -120,7 +121,12 @@ elif [ -n "$domain" ] && [ -z "$down" ]; then
|
|||
docker build $FLIGHTS_INFORMATION -f $FLIGHTS_INFORMATION/Dockerfile.test -t $USER/flights-information:test
|
||||
export API_IMAGE=$USER/flights-information:test
|
||||
docker compose -f flights-domain/docker-compose.dev.yml --env-file flights-domain/.env.dev down
|
||||
if [ -n "$integration" ]; then
|
||||
export TEST_TARGET=INTEGRATION
|
||||
docker compose -f flights-domain/docker-compose.dev.yml --env-file flights-domain/.env.dev up -d
|
||||
else
|
||||
docker compose -f flights-domain/docker-compose.dev.yml --env-file flights-domain/.env.dev up --abort-on-container-exit
|
||||
fi
|
||||
else
|
||||
export API_IMAGE=$USER/flights-information:prod
|
||||
docker compose -f flights-domain/docker-compose.yml --env-file flights-domain/.env.prod down
|
||||
|
@ -135,7 +141,12 @@ elif [ -n "$domain" ] && [ -z "$down" ]; then
|
|||
docker build $SUBSCRIPTION_MANAGER -f $SUBSCRIPTION_MANAGER/Dockerfile.test -t $USER/subs-manager:test
|
||||
export API_IMAGE=$USER/subs-manager:test
|
||||
docker compose -f subscription-domain/docker-compose.dev.yml --env-file subscription-domain/.env.dev down
|
||||
if [ -n "$integration" ]; then
|
||||
export TEST_TARGET=INTEGRATION
|
||||
docker compose -f subscription-domain/docker-compose.dev.yml --env-file subscription-domain/.env.dev up -d
|
||||
else
|
||||
docker compose -f subscription-domain/docker-compose.dev.yml --env-file subscription-domain/.env.dev up --abort-on-container-exit
|
||||
fi
|
||||
else
|
||||
export API_IMAGE=$USER/subs-manager:prod
|
||||
docker compose -f subscription-domain/docker-compose.yml --env-file subscription-domain/.env.prod down
|
||||
|
@ -149,7 +160,12 @@ elif [ -n "$domain" ] && [ -z "$down" ]; then
|
|||
docker build gateway -f gateway/Dockerfile.test -t $USER/gateway:test
|
||||
export API_IMAGE=$USER/gateway:test
|
||||
docker compose -f gateway/docker-compose.dev.yml --env-file gateway/.env.dev down
|
||||
if [ -n "$integration" ]; then
|
||||
export TEST_TARGET=INTEGRATION
|
||||
docker compose -f gateway/docker-compose.dev.yml --env-file gateway/.env.dev up -d
|
||||
else
|
||||
docker compose -f gateway/docker-compose.dev.yml --env-file gateway/.env.dev up --abort-on-container-exit
|
||||
fi
|
||||
else
|
||||
export API_IMAGE=$USER/gateway:prod
|
||||
docker compose -f gateway/docker-compose.yml --env-file gateway/.env.prod down
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
API_URL=http://localhost:5000
|
|
@ -0,0 +1,18 @@
|
|||
FROM slococo/python-builder:3.11.2
|
||||
|
||||
USER root
|
||||
RUN apt update && apt install libpq-dev -y
|
||||
|
||||
USER 999
|
||||
RUN python -m pip install --upgrade pip && \
|
||||
python -m pip install catcher catcher-modules[postgres]
|
||||
|
||||
COPY --chown=python:python . .
|
||||
RUN chmod +x /usr/src/app/test.sh
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE 1
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
ARG API_URL
|
||||
ENV API_URL $API_URL
|
||||
|
||||
ENTRYPOINT ["/usr/src/app/test.sh"]
|
|
@ -0,0 +1,33 @@
|
|||
version: '3.8'
|
||||
|
||||
services:
|
||||
catcher:
|
||||
container_name: fids-testing_catcher
|
||||
image: ${API_IMAGE}
|
||||
environment:
|
||||
- API_URL=${API_URL}
|
||||
# entrypoint: ["/bin/bash","-c"]
|
||||
# command:
|
||||
# - "sleep 120"
|
||||
networks:
|
||||
- auth
|
||||
- flights
|
||||
- gateway
|
||||
- subscriptions
|
||||
- catcher
|
||||
|
||||
networks:
|
||||
auth:
|
||||
name: fids-auth-dev_auth
|
||||
external: true
|
||||
flights:
|
||||
name: fids-flights-dev_flights
|
||||
external: true
|
||||
subscriptions:
|
||||
name: fids-subs-dev_subscriptions
|
||||
external: true
|
||||
gateway:
|
||||
name: fids-gateway-dev_gateway
|
||||
external: true
|
||||
catcher:
|
||||
driver: bridge
|
|
@ -0,0 +1,4 @@
|
|||
postgres: 'user:password@auth-db:5432/api_dev'
|
||||
users: 'http://fids-auth-dev_auth-api:5000/users'
|
||||
auth: 'http://fids-auth-dev_auth-api:5000/auth'
|
||||
gateway: 'http://fids-gateway-dev_api-gw:5002'
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
catcher -i inventories/local.yaml tests/*.yaml
|
|
@ -0,0 +1,25 @@
|
|||
variables:
|
||||
users:
|
||||
- email: 'info@lufthansa.com'
|
||||
password: 'password1234'
|
||||
steps:
|
||||
- http:
|
||||
post:
|
||||
url: '{{ gateway }}/auth/login'
|
||||
body: '{{ users[0] }}'
|
||||
headers: {Content-Type: 'application/json'}
|
||||
response_code: 2xx
|
||||
name: 'Login with {{ users[0].email }}'
|
||||
register: {user_id: '{{ OUTPUT.user_id }}'}
|
||||
- postgres:
|
||||
request:
|
||||
conf: '{{ postgres }}'
|
||||
sql: 'select * from users where id = {{ user_id }}'
|
||||
register: {email_in_db: '{{ OUTPUT.email }}'}
|
||||
- check:
|
||||
equals: {the: '{{ users[0].email }}', is: '{{ email_in_db }}'}
|
||||
# finally:
|
||||
# - postgres:
|
||||
# request:
|
||||
# conf: '{{ postgres }}'
|
||||
# sql: 'delete from users where id = {{ user_id }}'
|
|
@ -0,0 +1 @@
|
|||
API_URL=http://localhost:5000
|
|
@ -0,0 +1,82 @@
|
|||
{
|
||||
"info": {
|
||||
"_postman_id": "5a442e31-1ca6-4662-bb2a-4a4fdcf89cb2",
|
||||
"name": "Auth",
|
||||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
|
||||
"_exporter_id": "31564770"
|
||||
},
|
||||
"item": [
|
||||
{
|
||||
"name": "Login",
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"exec": [
|
||||
"pm.test(\"Status code is 200\", function () {",
|
||||
" pm.response.to.have.status(200);",
|
||||
"});",
|
||||
"",
|
||||
"pm.test(\"Content-Type is present\", function () {",
|
||||
" pm.response.to.have.header(\"Content-Type\");",
|
||||
"});",
|
||||
""
|
||||
],
|
||||
"type": "text/javascript"
|
||||
}
|
||||
}
|
||||
],
|
||||
"request": {
|
||||
"method": "POST",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"email\": \"info@lufthansa.com\",\n \"password\": \"password1234\"\n}",
|
||||
"options": {
|
||||
"raw": {
|
||||
"language": "json"
|
||||
}
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{API_URL}}/auth/login",
|
||||
"host": [
|
||||
"{{API_URL}}"
|
||||
],
|
||||
"path": [
|
||||
"auth",
|
||||
"login"
|
||||
]
|
||||
}
|
||||
},
|
||||
"response": []
|
||||
}
|
||||
],
|
||||
"event": [
|
||||
{
|
||||
"listen": "prerequest",
|
||||
"script": {
|
||||
"type": "text/javascript",
|
||||
"exec": [
|
||||
""
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"type": "text/javascript",
|
||||
"exec": [
|
||||
""
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"variable": [
|
||||
{
|
||||
"key": "API_URL",
|
||||
"value": "http://localhost:5001",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
FROM node:16-alpine
|
||||
|
||||
ENV LC_ALL="en_US.UTF-8" LANG="en_US.UTF-8" LANGUAGE="en_US.UTF-8" ALPINE_NODE_REPO="oznu/alpine-node"
|
||||
|
||||
RUN npm install --global newman
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY . .
|
||||
RUN chmod +x /usr/src/app/test.sh
|
||||
|
||||
ENTRYPOINT ["/usr/src/app/test.sh"]
|
|
@ -0,0 +1,9 @@
|
|||
version: '3.8'
|
||||
|
||||
services:
|
||||
newman:
|
||||
container_name: fids-testing_newman
|
||||
image: ${API_IMAGE}
|
||||
environment:
|
||||
- API_URL=${API_URL}
|
||||
network_mode: host
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
newman run Auth.postman_collection.json
|
|
@ -0,0 +1,4 @@
|
|||
Dockerfile
|
||||
docker-compose.yml
|
||||
.dockerignore
|
||||
.gitignore
|
|
@ -0,0 +1 @@
|
|||
API_URL=http://localhost:5000
|
|
@ -0,0 +1,14 @@
|
|||
FROM slococo/python-builder:3.11.2
|
||||
|
||||
RUN python -m pip install --upgrade pip && \
|
||||
python -m pip install tavern
|
||||
|
||||
COPY --chown=python:python . .
|
||||
RUN chmod +x /usr/src/app/test.sh
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE 1
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
ARG API_URL
|
||||
ENV API_URL $API_URL
|
||||
|
||||
ENTRYPOINT ["/usr/src/app/test.sh"]
|
|
@ -0,0 +1,9 @@
|
|||
version: '3.8'
|
||||
|
||||
services:
|
||||
tavern:
|
||||
container_name: fids-testing_tavern
|
||||
image: ${API_IMAGE}
|
||||
environment:
|
||||
- API_URL=${API_URL}
|
||||
network_mode: host
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
tavern-ci *.yaml
|
|
@ -0,0 +1,9 @@
|
|||
test_name: Flights
|
||||
|
||||
stages:
|
||||
- name: Make sure we can get flights
|
||||
request:
|
||||
url: "{tavern.env_vars.API_URL}/flights"
|
||||
method: GET
|
||||
response:
|
||||
status_code: 200
|
|
@ -0,0 +1,20 @@
|
|||
test_name: Users
|
||||
|
||||
stages:
|
||||
- name: Make sure we can log in
|
||||
request:
|
||||
url: "{tavern.env_vars.API_URL}/auth/login"
|
||||
method: POST
|
||||
json:
|
||||
email: info@lufthansa.com
|
||||
password: password1234
|
||||
headers:
|
||||
content-type: application/json
|
||||
response:
|
||||
status_code: 200
|
||||
json:
|
||||
user_id: 1
|
||||
access_token: !anystr
|
||||
refresh_token: !anystr
|
||||
headers:
|
||||
content-type: application/json
|
Loading…
Reference in New Issue