#!/usr/bin/env bash

set -euo pipefail

ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
test_dir=$(mktemp -d)
trap 'rm -rf "$test_dir"' EXIT

run_byoc_case() {
  local key=$1
  local args_file="$test_dir/${key}.json"
  printf '{"%s": true}\n' "$key" >"$args_file"

  output=$(bash "$ROOT/deploy-new-region.sh" aws dev us-west-2 test-region test-cluster "$args_file")
  grep -Fq "Skip external-dns for AWS BYOC region test-region" <<<"$output"
  test ! -e "$ROOT/envs/dev-aws-test-region"
}

run_byoc_case isByoc
run_byoc_case byoc

echo "external-dns deploy-new-region tests passed"
