Skip to content

Commit

Permalink
Added test for dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
HeeManSu committed Jun 14, 2024
1 parent 6cdab86 commit df2be55
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 37 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jobs:
docker compose build
docker compose up --exit-code-from test
TEST_FAAS_STARTUP_DEPLOY=true docker compose up --exit-code-from test
TEST_FAAS_DEPENDENCY_DEPLOY=true docker compose up --exit-code-from test
docker compose down
- name: Publish
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ services:
target: test
environment:
TEST_FAAS_STARTUP_DEPLOY: ${TEST_FAAS_STARTUP_DEPLOY:-false}
TEST_FAAS_DEPENDENCY_DEPLOY: ${TEST_FAAS_DEPENDENCY_DEPLOY:-true}
network_mode: host
depends_on:
- faas
Expand Down
19 changes: 19 additions & 0 deletions test/data/python-dependency-app/handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import requests

# Fetch random joke function
def fetchJoke():
try:
response = requests.get('https://official-joke-api.appspot.com/random_joke')
response.raise_for_status() # Raise an error for bad status codes
joke = response.json()
return {
'setup': joke['setup'],
'punchline': joke['punchline']
}
except requests.RequestException as e:
return {'message': 'Error fetching joke', 'error': str(e)}

# Example usage
if __name__ == "__main__":
joke = fetchJoke()
print(joke)
5 changes: 5 additions & 0 deletions test/data/python-dependency-app/metacall.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"language_id": "py",
"path": ".",
"scripts": ["handler.py"]
}
1 change: 1 addition & 0 deletions test/data/python-dependency-app/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests
103 changes: 66 additions & 37 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,48 +60,77 @@ done

echo "FaaS ready, starting tests."

# Test deploy (Python) without dependencies
app="python-base-app"
pushd data/$app
deploy
prefix=$(getPrefix $app)
url=$BASE_URL/$prefix/$app/v1/call
[[ $(curl -s $url/number) = 100 ]] || exit 1
[[ $(curl -s $url/text) = '"asd"' ]] || exit 1
popd

# Test inspect
echo "Testing inspect functionality."

# Inspect the deployed projects
inspect_response=$(curl -s $BASE_URL/api/inspect)

# Verify inspection
if [[ $inspect_response != *"$prefix"* ]]; then
echo "Inspection test failed."
exit 1
fi
# Function to run tests
function run_tests() {
local app=$1
local test_func=$2

pushd data/$app
deploy
prefix=$(getPrefix $app)
url=$BASE_URL/$prefix/$app/v1/call
$test_func $url
popd

# Test inspect
echo "Testing inspect functionality."

# Inspect the deployed projects
inspect_response=$(curl -s $BASE_URL/api/inspect)

# Verify inspection
if [[ $inspect_response != *"$prefix"* ]]; then
echo "Inspection test failed."
exit 1
fi

# Verify packages are included in the response
if [[ $inspect_response != *"packages"* ]]; then
echo "packages not found in inspection response."
exit 1
fi
# Verify packages are included in the response
if [[ $inspect_response != *"packages"* ]]; then
echo "packages not found in inspection response."
exit 1
fi

echo "Inspection test passed."
echo "Inspection test passed."

# Test delete functionality
echo "Testing delete functionality."

# Delete the deployed project
curl -X POST -H "Content-Type: application/json" -d '{"suffix":"'"$app"'","prefix":"'"$prefix"'","version":"v1"}' $BASE_URL/api/deploy/delete

# Verify deletion
if [[ "$app" == "python-dependency-app" ]]; then
if [[ $(curl -s -o /dev/null -w "%{http_code}" $BASE_URL/$prefix/$app/v1/call/fetchJoke) != "404" ]]; then
echo "Deletion test failed."
exit 1
fi
else
if [[ $(curl -s -o /dev/null -w "%{http_code}" $BASE_URL/$prefix/$app/v1/call/number) != "404" ]]; then
echo "Deletion test failed."
exit 1
fi
fi

echo "Deletion test passed."
}

# Test delete only if we are not testing startup deployments
echo "Testing delete functionality."
# Test function for python-base-app
function test_python_base_app() {
local url=$1
[[ $(curl -s $url/number) = 100 ]] || exit 1
[[ $(curl -s $url/text) = '"asd"' ]] || exit 1
}

# Delete the deployed project
curl -X POST -H "Content-Type: application/json" -d '{"suffix":"python-base-app","prefix":"'"$prefix"'","version":"v1"}' $BASE_URL/api/deploy/delete
# Test function for python-dependency-app
function test_python_dependency_app() {
local url=$1
[[ $(curl -s $url/fetchJoke) == *"setup"* && $(curl -s $url/fetchJoke) == *"punchline"* ]] || exit 1
}

# Verify deletion
if [[ $(curl -s -o /dev/null -w "%{http_code}" $BASE_URL/$prefix/$app/v1/call/number) != "404" ]]; then
echo "Deletion test failed."
exit 1
# Run tests without dependencies
run_tests "python-base-app" test_python_base_app
if [[ "${TEST_FAAS_DEPENDENCY_DEPLOY}" == "true" ]]; then
run_tests "python-dependency-app" test_python_dependency_app
fi

echo "Deletion test passed."

echo "Integration tests passed without errors."

0 comments on commit df2be55

Please sign in to comment.