Skip to content

Commit

Permalink
Issue #234: Added curl tester
Browse files Browse the repository at this point in the history
Signed-off-by: alexmerlin <[email protected]>
  • Loading branch information
alexmerlin committed May 17, 2024
1 parent 195077e commit 66d48b9
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
Expand All @@ -34,7 +34,7 @@ jobs:
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/curl-tester.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Run curl tester

on:
pull_request:
push:
branches:
- 4.0

jobs:
run-bash:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Make curl tester executable
run: chmod +x ./test/tester.sh

- name: Run curl tester
run: ./test/tester.sh
48 changes: 48 additions & 0 deletions test/curl-tester.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# Bootstrap

OK=''
KO=''

if ! command -v curl > /dev/null 2>&1; then
echo "$KO curl is not installed"
exit 1
fi

# Define globals

body=""
status_code=0

# Functions

send_request() {
response=$(curl -s -w "\n%{http_code}" $1)

body=$(echo "$response" | sed '$d')
status_code=$(echo "$response" | tail -n 1)
}

get() {
send_request $1
}

post() {
send_request $1
}

# Endpoints

endpoint_home="https://api.dotkernel.net"

# Tests

get $endpoint_home

if echo "$body" | grep -q '{"message":"Welcome to DotKernel API!" }'; then
echo "$OK $endpoint_home: SUCCESS ($status_code)"
else
echo "$KO $endpoint_home: FAILED ($status_code)"
exit 1
fi

0 comments on commit 66d48b9

Please sign in to comment.