#!/bin/bash

# Copyright 2020 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

###############################################################################

# This script is executed by presubmit `pull-cluster-api-provider-azure-e2e`
# To run locally, set PACKET_API_KEY, PROJECT_ID, ``

set -o errexit
set -o nounset
set -o pipefail

REPO_ROOT=$(realpath $(dirname "${BASH_SOURCE[0]}")/..)
cd "${REPO_ROOT}" || exit 1

# Make sure the tools binaries are on the path.
export PATH="${REPO_ROOT}/hack/tools/bin:${PATH}"

# shellcheck source=../hack/ensure-go.sh
source "${REPO_ROOT}/hack/ensure-go.sh"

# Verify the required Environment Variables are present.
: "${PACKET_API_KEY:?Environment variable empty or not defined.}"
: "${PROJECT_ID:?Environment variable empty or not defined.}"
: "${METRO:?Environment variable empty or not defined.}"
: "${CONTROLPLANE_NODE_TYPE:?Environment variable empty or not defined.}"
: "${WORKER_NODE_TYPE:?Environment variable empty or not defined.}"

# Avoid running the tests that require a published image, unless
# running within GitHub Actions (CI=true)
if [[ "${CI:-""}" == "true" ]]; then
    make test-e2e-ci
else
    make test-e2e-local
fi
