Skip to content

Commit

Permalink
restructuring
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 eb076c7 commit 4b9acbe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
33 changes: 5 additions & 28 deletions test/curl-tester.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,16 @@ if ! command -v curl > /dev/null 2>&1; then
exit 1
fi

# Define globals
. test/curl/endpoints.sh
. test/curl/functions.sh

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)"
if echo "$body" | grep -q 'Welcome'; then
echo "$OK $endpoint_home: $status_code"
else
echo "$KO $endpoint_home: FAILED ($status_code)"
echo "$KO $endpoint_home: $status_code"
exit 1
fi
1 change: 1 addition & 0 deletions test/curl/endpoints.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
endpoint_home="https://api.dotkernel.net"
14 changes: 14 additions & 0 deletions test/curl/functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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
}

0 comments on commit 4b9acbe

Please sign in to comment.