#!/bin/bash
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
#

# This script patches the new runtime crates into an old AWS SDK and runs tests
# to check for semver hazards, such as a `Storable` being in an unstable runtime crate.

C_YELLOW='\033[1;33m'
C_RESET='\033[0m'

if [ "$#" -ne 0 ]; then
  echo "Unexpected arguments ignored"
fi

# Need to allow warnings since there may be deprecations that the old SDK uses
unset RUSTFLAGS

set -eux

echo -e "${C_YELLOW}# Patching SDK...${C_RESET}"
runtime-versioner patch-runtime \
  --sdk-path "$(pwd)/aws-sdk-rust" \
  --smithy-rs-path "$(pwd)/smithy-rs"

echo -e "${C_YELLOW}# Testing SDK...${C_RESET}"
for sdk in aws-sdk-rust/sdk/*; do
  if ls "$sdk/tests" | grep -v '^endpoint_tests\.rs$'; then
    echo -e "${C_YELLOW}# Testing ${sdk}...${C_RESET}"
    pushd "$sdk" &>/dev/null
    cargo test --all-features
    popd &>/dev/null
  fi
done
