MF-643 - Create end-to-end tests for openAPI #17
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test OpenAPI using Schemathesis | |
on: [push, pull_request] | |
env: | |
# MF_TOKEN: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NzM5MTgxNjUsImlhdCI6MTY3Mzg4MjE2NSwiaXNzIjoibWFpbmZsdXguYXV0aCIsInN1YiI6ImV4YW1wbGVAZWcuY29tIiwiaXNzdWVyX2lkIjoiNzE0NTk5MmYtMzZkZi00NjE5LWE1YzQtOGJkMzg2YjI3YmE5IiwidHlwZSI6MH0.W7Ra3ChV0PPfTTJGJX4hAW_1Gq2zK0RR9qJJm3sk5tw" | |
# To check if the MF_TOKEN gets updated in subsequent steps (big string gets displayed as ... , so I can't test) | |
MF_TOKEN: abcd | |
EMAIL: admin@example.com | |
PASSWORD: 12345678 | |
DEVICE: mf-device | |
jobs: | |
api-tests: | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: checkout repo | |
uses: actions/checkout@v2 | |
- name: find number of cores | |
run: lscpu | egrep 'Model name|Socket|Thread|NUMA|CPU\(s\)' | |
# - name: Check Git Configuration | |
# run: git config --list # Print Git configuration | |
# # - name: Check Version Var | |
# # run: git describe --abbrev=0 --tags | |
# # - name: Check Version Var Always | |
# # run: git describe --abbrev=0 --tags --always | |
# # - name: Fetch Tags from Upstream | |
# # run: git fetch --tags https://github.com/mainflux/mainflux.git | |
- name: create images | |
if: always() | |
run: make all -j 2 && make -j 2 dockers_dev | |
- name: run containers | |
if: always() | |
run: make run ARGS="-d" | |
- name: REST API with curl to provision user | |
if: always() | |
run: | | |
curl -sSiX POST http://localhost:9002/users -H "Content-Type: application/json" -d '{"name": "John Doe","credentials": {"identity": "admin@example.com","secret": "12345678"}}' | |
# - name: REST API with curl to check mf token endpoint | |
# if: always() | |
# run: | | |
# curl -X POST "http://localhost:9002/users/tokens/issue" -H "Content-Type: application/json" -d '{"identity": "admin@example.com","secret": "12345678"}' | |
- name: Set ACCESS_TOKEN | |
id: set-access-token | |
run: | | |
response='{"access_token":"..." ... }' # Replace with your JSON response | |
access_token=$(echo "$response" | grep -o '"access_token":"[^"]*' | cut -d'"' -f4) | |
echo "ACCESS_TOKEN=$access_token" >> $GITHUB_ENV | |
- name: print mf token | |
if: always() | |
run: echo $MF_TOKEN | |
- name: Set token env variable | |
run: echo "MF_TOKEN=$(echo $MF_TOKEN)" >> $GITHUB_ENV | |
- name: Test | |
run: echo ${{ env.MF_TOKEN }} | |
# Bootstrap.yml | |
# - name: Run st for bootstrap.yml | |
# if: always() | |
# uses: schemathesis/action@v1 | |
# with: | |
# schema: './api/openapi/bootstrap.yml' | |
# base-url: 'http://localhost' | |
# args: -H Authorization:${{ env.MF_TOKEN }} | |
# token: ${{ secrets.SCHEMATHESIS_TOKEN }} | |
# - name: Run st for bootstrap.yml | |
# if: always() | |
# uses: schemathesis/action@v1 | |
# with: | |
# schema: './api/openapi/bootstrap.yml' | |
# base-url: 'http://localhost' | |
# args: -H Authorization: Bearer ${{ env.ACCESS_TOKEN }} | |
# token: ${{ secrets.SCHEMATHESIS_TOKEN }} | |
- name: Run st for bootstrap.yml | |
if: always() | |
uses: schemathesis/action@v1 | |
with: | |
schema: './api/openapi/bootstrap.yml' | |
base-url: 'http://localhost' | |
args: "--headers=Authorization: Bearer ${{ env.ACCESS_TOKEN }}" | |
token: ${{ secrets.SCHEMATHESIS_TOKEN }} | |
# Certs.yml | |
- name: Run st for certs.yml | |
if: always() | |
uses: schemathesis/action@v1 | |
with: | |
schema: './api/openapi/certs.yml' | |
base-url: 'http://localhost' | |
args: -H Authorization:${{ env.MF_TOKEN }} | |
token: ${{ secrets.SCHEMATHESIS_TOKEN }} | |
# Consumers-notifiers.yml | |
- name: Run st for consumers-notifiers.yml | |
if: always() | |
uses: schemathesis/action@v1 | |
with: | |
schema: './api/openapi/consumers-notifiers.yml' | |
base-url: 'http://localhost' | |
args: -H Authorization:${{ env.MF_TOKEN }} | |
token: ${{ secrets.SCHEMATHESIS_TOKEN }} | |
# Http.yml | |
- name: Run st for http.yml | |
if: always() | |
uses: schemathesis/action@v1 | |
with: | |
schema: './api/openapi/http.yml' | |
base-url: 'http://localhost' | |
args: -H Authorization:${{ env.MF_TOKEN }} | |
token: ${{ secrets.SCHEMATHESIS_TOKEN }} | |
# Provision.yml | |
- name: Run st for provision.yml | |
if: always() | |
uses: schemathesis/action@v1 | |
with: | |
schema: './api/openapi/provision.yml' | |
base-url: 'http://localhost' | |
args: -H Authorization:${{ env.MF_TOKEN }} | |
token: ${{ secrets.SCHEMATHESIS_TOKEN }} | |
# Readers.yml | |
- name: Run st for readers.yml | |
if: always() | |
uses: schemathesis/action@v1 | |
with: | |
schema: './api/openapi/readers.yml' | |
base-url: 'http://localhost' | |
args: -H Authorization:${{ env.MF_TOKEN }} | |
token: ${{ secrets.SCHEMATHESIS_TOKEN }} | |
# Things.yml | |
- name: Run st for things.yml | |
if: always() | |
uses: schemathesis/action@v1 | |
with: | |
schema: './api/openapi/things.yml' | |
base-url: 'http://localhost' | |
args: -H Authorization:${{ env.MF_TOKEN }} | |
token: ${{ secrets.SCHEMATHESIS_TOKEN }} | |
# Twins.yml | |
- name: Run st for twins.yml | |
if: always() | |
uses: schemathesis/action@v1 | |
with: | |
schema: './api/openapi/twins.yml' | |
base-url: 'http://localhost' | |
args: -H Authorization:${{ env.MF_TOKEN }} | |
token: ${{ secrets.SCHEMATHESIS_TOKEN }} | |
# Users.yml | |
- name: Run st for users.yml | |
if: always() | |
uses: schemathesis/action@v1 | |
with: | |
schema: './api/openapi/users.yml' | |
base-url: 'http://localhost' | |
args: -H Authorization:${{ env.MF_TOKEN }} | |
token: ${{ secrets.SCHEMATHESIS_TOKEN }} | |
# Websocket.yml | |
- name: Run st for websocket.yml | |
if: always() | |
uses: schemathesis/action@v1 | |
with: | |
schema: './api/openapi/websocket.yml' | |
base-url: 'http://localhost' | |
args: -H Authorization:${{ env.MF_TOKEN }} | |
token: ${{ secrets.SCHEMATHESIS_TOKEN }} | |
- name: Stop the running docker containers | |
if: always() | |
run: make stop |