From 822914ea59e05f43b9b0aea9671581599935eb4a Mon Sep 17 00:00:00 2001 From: Himanshu Kumar Sharma <97340980+HeeManSu@users.noreply.github.com> Date: Fri, 7 Jun 2024 19:24:58 +0530 Subject: [PATCH] Delete and inspect test (#51) * delete and inspect test added * package undefined issue solved * echo removed * delete test removed * auto deploy test fixed * ci fixed * Revet to old package-lock.json * Tabs for indentation * Indentation corrected --- src/controller/inspect.ts | 4 ++++ src/worker/index.ts | 5 +++-- test/test.sh | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/controller/inspect.ts b/src/controller/inspect.ts index 7f6daac..ca1b0ac 100644 --- a/src/controller/inspect.ts +++ b/src/controller/inspect.ts @@ -8,6 +8,10 @@ export const inspect = (_req: Request, res: Response): Response => { for (const application of Object.values(Applications)) { // Check if the application is deployed if (application.deployment) { + // Ensure packages is not undefined or null + if (!application.deployment.packages) { + throw new Error('Packages is undefined or null'); + } deployments.push(application.deployment); } } diff --git a/src/worker/index.ts b/src/worker/index.ts index 8ac7798..c82e309 100644 --- a/src/worker/index.ts +++ b/src/worker/index.ts @@ -1,6 +1,6 @@ /* eslint-disable */ -import { Deployment, MetaCallJSON } from '@metacall/protocol'; +import { Deployment, LanguageId, MetaCallJSON } from '@metacall/protocol'; import { findFilesPath, findMetaCallJsons } from '@metacall/protocol/package'; import { promises as fs } from 'fs'; import { @@ -54,7 +54,8 @@ const loadDeployment = ( throw new Error(`language_id not found in ${path}`); } - deployment.packages = inspect[json.language_id][path]; + deployment.packages[json.language_id as LanguageId] = + inspect[json.language_id]; // Store the functions Object.keys(exports).forEach(func => { diff --git a/test/test.sh b/test/test.sh index e41be3e..a94d93e 100755 --- a/test/test.sh +++ b/test/test.sh @@ -53,3 +53,41 @@ pushd data/$app [[ $(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 + +# 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." + +# Test delete only if we are not testing startup deployments +if [[ "${TEST_FAAS_STARTUP_DEPLOY}" == "true" ]]; then + echo "Testing delete functionality." + + # 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 + + # 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 + fi + + echo "Deletion test passed." +fi + +echo "Integration tests passed without errors." \ No newline at end of file