Skip to content

Commit

Permalink
Merge branch 'main' into jbe/better_bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins committed Nov 13, 2024
2 parents 4f6c758 + 294f409 commit eca516a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 49 deletions.
1 change: 1 addition & 0 deletions scripts/codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ rm -rf SmokeTests/*
cd AWSSDKSwiftCLI
unset AWS_SWIFT_SDK_USE_LOCAL_DEPS
swift run AWSSDKSwiftCLI generate-package-manifest "$@" ..
swift run AWSSDKSwiftCLI generate-smoke-tests-package-manifest ..
swift run AWSSDKSwiftCLI generate-doc-index ..
cd ..

Expand Down
84 changes: 35 additions & 49 deletions scripts/run-smoke-tests.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/bin/bash

# This script must be run from the directory containing aws-sdk-swift.
SMOKE_TESTS_DIR="aws-sdk-swift/SmokeTests/"
cd "$SMOKE_TESTS_DIR" || { echo "ERROR: Failed to change directory to $SMOKE_TESTS_DIR"; exit 1; }

print_header() {
local header=$1
print_empty_line
Expand All @@ -15,69 +11,59 @@ print_empty_line() {
echo ""
}

print_header "SETUP SMOKE TESTS"
print_header "SETTING UP SMOKE TESTS"

# Clean build
swift package clean > /dev/null 2>&1
# This script must be run from . that contains smoke test runner executables under ./Executables.
SMOKE_TESTS_DIR="./Executables"
if [[ -d "$SMOKE_TESTS_DIR" ]]; then
echo "INFO: Directory '$SMOKE_TESTS_DIR' exists in $(pwd)."
else
echo "ERROR: Directory '$SMOKE_TESTS_DIR' does not exist in $(pwd)."
exit 1
fi

# Expect comma-separated service names from AWS_SMOKE_TEST_SERVICE_IDS environment variable.
# The service names in environment variable must be in the format "AWSName", e.g., "AWSS3".
# Expect comma-separated sdkId's from AWS_SMOKE_TEST_SERVICE_IDS environment variable.
# Each sdkId is processed following same logic as in Swift codegen.
# The resulting array will be in the format "AWSNameSmokeTestRunner", e.g., "AWSS3SmokeTestRunner".
if [ -z "$AWS_SMOKE_TEST_SERVICE_IDS" ]; then
# If env var isn't set, exit script
echo "INFO: The environment variable AWS_SMOKE_TEST_SERVICE_IDS is not set or is empty."
echo "INFO: It must set to a comma-separated string of service names for which you want to run smoke test for."
echo "INFO: Exiting run-smoke-tests.sh with exit code 0."
exit 0
else
IFS=',' read -r -a testRunnerNames <<< "$AWS_SMOKE_TEST_SERVICE_IDS"
for i in "${!testRunnerNames[@]}"; do
testRunnerNames[$i]="${testRunnerNames[$i]}SmokeTestRunner"
# Remove whitespace from sdkId
value="${testRunnerNames[$i]// /}"

# Capitalize the first letter of sdkId
value="$(echo "${value:0:1}" | tr '[:lower:]' '[:upper:]')${value:1}"

# Remove "Service" suffix from sdkId if it exists
value="${value%Service}"

# Add "AWS" prefix and "SmokeTestRunner" suffix to the modified value
value="AWS${value}SmokeTestRunner"

# Update the original array with the modified value
testRunnerNames[$i]="$value"
done
echo "INFO: Retrieved the value of AWS_SMOKE_TEST_SERVICE_IDS: $AWS_SMOKE_TEST_SERVICE_IDS."
echo "INFO: Constructed test runner names: ${testRunnerNames[@]}"
echo "INFO: Retrieved value of \$AWS_SMOKE_TEST_SERVICE_IDS env var: \"$AWS_SMOKE_TEST_SERVICE_IDS\""
IFS=','; echo "INFO: Constructed test runner names: [${testRunnerNames[*]}]"
fi

# Array of test failure logs.
testFailureLogs=()

print_header "RUN SMOKE TESTS"
print_header "RUNNING SMOKE TESTS"

for testRunnerName in "${testRunnerNames[@]}"; do
# If test runner was generated under SmokeTests/
if [ -d "$testRunnerName" ]; then
echo "INFO: Found smoke tests for the service ${testRunnerName%SmokeTestRunner}."
echo "INFO: Building smoke test(s) for the service ${testRunnerName%SmokeTestRunner}..."
# Build the test runner executable (discard output for clean log)
swift build --target "$testRunnerName" > /dev/null 2>&1
echo "INFO: Running smoke test(s) for the service ${testRunnerName%SmokeTestRunner}..."
# Run executable and save output to `testRunOutput`
testRunOutput=$(swift run --quiet "$testRunnerName")
# Get test runner exit code
testRunExitCode=$?
# If exit code was 1, one or more tests failed. Save its output to array.
if [ "$testRunExitCode" -eq 1 ]; then
testFailureLogs+=("$testRunOutput")
fi
# If test runner executable exists under ./Executables/
if [ -x "./Executables/$testRunnerName" ]; then
echo "INFO: Running ${testRunnerName}..."
# Run executable
./Executables/"$testRunnerName"
print_empty_line
# If no smoke tests were generated, no-op
else
echo "INFO: No smoke tests found for the service ${testRunnerName%SmokeTestRunner}. Skipping..."
echo "INFO: ${testRunnerName} not found. Skipping..."
print_empty_line
fi
done

print_header "SMOKE TEST RESULTS"

# Log any failure outputs if present and exit with 1
if [ ${#testFailureLogs[@]} -gt 0 ]; then
echo "# One or more smoke test(s) failed. See the log(s) for failed test runner(s) below:"
print_empty_line
for failureLog in "${testFailureLogs[@]}"; do
echo "${failureLog}"
print_empty_line
done
exit 1
else
echo "INFO: Every smoke test for every service passed!"
exit 0
fi

0 comments on commit eca516a

Please sign in to comment.