github.com/cornelk/go-cloud@v0.17.1/internal/testing/prerelease.sh (about)

     1  #!/usr/bin/env bash
     2  # Copyright 2019 The Go Cloud Development Kit Authors
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #     https://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  # This script runs expensive checks that we don't normally run on Travis, but
    17  # that should run periodically, before each release.
    18  # For example, tests that can't use record/replay, so must be performed live
    19  # against the backing service.
    20  #
    21  # It should be run from the root directory.
    22  
    23  # https://coderwall.com/p/fkfaqq/safer-bash-scripts-with-set-euxo-pipefail
    24  # Change to -euxo if debugging.
    25  set -euo pipefail
    26  
    27  function usage() {
    28    echo
    29    echo "Usage: prerelease.sh <init | run | cleanup>" 1>&2
    30    echo "  init: creates any needed resources; rerun until it succeeds"
    31    echo "  run: runs all needed checks"
    32    echo "  cleanup: cleans up resources created in init"
    33    exit 64
    34  }
    35  
    36  if [[ $# -ne 1 ]] ; then
    37    echo "Need at least one argument."
    38    usage
    39  fi
    40  
    41  op="$1"
    42  case "$op" in
    43    init|run|cleanup);;
    44    *) echo "Unknown operation '$op'" && usage;;
    45  esac
    46  
    47  # TODO: It would be nice to ensure that none of the tests are skipped. For now,
    48  #       we assume that if the "init" steps succeeded, the necessary tests will
    49  #       run.
    50  
    51  rootdir="$(pwd)"
    52  FAILURES=""
    53  
    54  TESTDIR="mysql/azuremysql"
    55  echo "***** $TESTDIR *****"
    56  pushd "$TESTDIR" &> /dev/null
    57  case "$op" in
    58    init)
    59      terraform init && terraform apply -var location="centralus" -var resourcegroup="GoCloud" -auto-approve || FAILURES="$FAILURES $TESTDIR"
    60      ;;
    61    run)
    62      go test -mod=readonly -race -json | go run "$rootdir"/internal/testing/test-summary/test-summary.go -progress || FAILURES="$FAILURES $TESTDIR"
    63      ;;
    64    cleanup)
    65      terraform destroy -var location="centralus" -var resourcegroup="GoCloud" -auto-approve || FAILURES="$FAILURES $TESTDIR"
    66      ;;
    67  esac
    68  popd &> /dev/null
    69  
    70  
    71  TESTDIR="mysql/gcpmysql"
    72  echo
    73  echo "***** $TESTDIR *****"
    74  pushd "$TESTDIR" &> /dev/null
    75  case "$op" in
    76    init)
    77      terraform init && terraform apply -var project="go-cloud-test-216917" -auto-approve || FAILURES="$FAILURES $TESTDIR"
    78      ;;
    79    run)
    80      go test -mod=readonly -race -json | go run "$rootdir"/internal/testing/test-summary/test-summary.go -progress || FAILURES="$FAILURES $TESTDIR"
    81      ;;
    82    cleanup)
    83      terraform destroy -var project="go-cloud-test-216917" -auto-approve || FAILURES="$FAILURES $TESTDIR"
    84      ;;
    85  esac
    86  popd &> /dev/null
    87  
    88  
    89  TESTDIR="mysql/awsmysql"
    90  echo
    91  echo "***** $TESTDIR *****"
    92  pushd "$TESTDIR" &> /dev/null
    93  case "$op" in
    94    init)
    95      terraform init && terraform apply -var region="us-west-1" -auto-approve || FAILURES="$FAILURES $TESTDIR"
    96      ;;
    97    run)
    98      go test -mod=readonly -race -json | go run "$rootdir"/internal/testing/test-summary/test-summary.go -progress || FAILURES="$FAILURES $TESTDIR"
    99      ;;
   100    cleanup)
   101      terraform destroy -var region="us-west-1" -auto-approve || FAILURES="$FAILURES $TESTDIR"
   102      ;;
   103  esac
   104  popd &> /dev/null
   105  
   106  
   107  TESTDIR="postgres/gcppostgres"
   108  echo
   109  echo "***** $TESTDIR *****"
   110  pushd "$TESTDIR" &> /dev/null
   111  case "$op" in
   112    init)
   113      terraform init && terraform apply -var project="go-cloud-test-216917" -auto-approve || FAILURES="$FAILURES $TESTDIR"
   114      ;;
   115    run)
   116      go test -mod=readonly -race -json | go run "$rootdir"/internal/testing/test-summary/test-summary.go -progress || FAILURES="$FAILURES $TESTDIR"
   117      ;;
   118    cleanup)
   119      terraform destroy -var project="go-cloud-test-216917" -auto-approve || FAILURES="$FAILURES $TESTDIR"
   120      ;;
   121  esac
   122  popd &> /dev/null
   123  
   124  
   125  TESTDIR="postgres/awspostgres"
   126  echo
   127  echo "***** $TESTDIR *****"
   128  pushd "$TESTDIR" &> /dev/null
   129  case "$op" in
   130    init)
   131      terraform init && terraform apply -var region="us-west-1" -auto-approve || FAILURES="$FAILURES $TESTDIR"
   132      ;;
   133    run)
   134      go test -mod=readonly -race -json  | go run "$rootdir"/internal/testing/test-summary/test-summary.go -progress || FAILURES="$FAILURES $TESTDIR"
   135      ;;
   136    cleanup)
   137      terraform destroy -var region="us-west-1" -auto-approve || FAILURES="$FAILURES $TESTDIR"
   138      ;;
   139  esac
   140  popd &> /dev/null
   141  
   142  
   143  # This iterates over all packages that have a "testdata" directory, using that
   144  # as a signal for record/replay tests, and runs the tests with a "-record" flag.
   145  # This verifies that we can generate a fresh recording against the live service.
   146  while read -r TESTDIR; do
   147    # Skip some packages that have a testdata/ dir but aren't record/replay.
   148    if [ "$TESTDIR" == "./samples/order" ]; then
   149      continue;
   150    fi
   151    echo
   152    echo "***** $TESTDIR *****"
   153    pushd "$TESTDIR" &> /dev/null
   154    case "$op" in
   155      init)
   156        ;;
   157      run)
   158        go test -mod=readonly -race -record -json | go run "$rootdir"/internal/testing/test-summary/test-summary.go -progress || FAILURES="$FAILURES $TESTDIR"
   159        ;;
   160      cleanup)
   161        ;;
   162    esac
   163    popd &> /dev/null
   164  done < <( find . -name testdata -printf "%h\\n" )
   165  
   166  echo
   167  echo
   168  if [ ! -z "$FAILURES" ]; then
   169    echo "FAILED!"
   170    echo "Investigate and re-run -record tests for the following packages: $FAILURES"
   171    exit 1
   172  fi
   173  
   174  echo "SUCCESS!"