diff --git a/test/curl-tester.sh b/test/curl-tester.sh index 960123b..28c1985 100755 --- a/test/curl-tester.sh +++ b/test/curl-tester.sh @@ -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 diff --git a/test/curl/endpoints.sh b/test/curl/endpoints.sh new file mode 100644 index 0000000..3718da8 --- /dev/null +++ b/test/curl/endpoints.sh @@ -0,0 +1 @@ +endpoint_home="https://api.dotkernel.net" diff --git a/test/curl/functions.sh b/test/curl/functions.sh new file mode 100644 index 0000000..d428119 --- /dev/null +++ b/test/curl/functions.sh @@ -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 +}