github.com/thiagoyeds/go-cloud@v0.26.0/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, 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 rerecord);; 45 *) echo "Unknown operation '$op'" && usage;; 46 esac 47 48 # TODO: It would be nice to ensure that none of the tests are skipped. For now, 49 # we assume that if the "init" steps succeeded, the necessary tests will 50 # run. 51 52 rootdir="$(pwd)" 53 FAILURES="" 54 55 TESTDIR="mysql/azuremysql" 56 echo "***** $TESTDIR *****" 57 pushd "$TESTDIR" &> /dev/null 58 case "$op" in 59 init) 60 terraform init && terraform apply -var location="centralus" -var resourcegroup="GoCloud" -auto-approve || FAILURES="$FAILURES $TESTDIR" 61 ;; 62 run) 63 go test -mod=readonly -race -json | go run "$rootdir"/internal/testing/test-summary/test-summary.go -progress || FAILURES="$FAILURES $TESTDIR" 64 ;; 65 cleanup) 66 terraform destroy -var location="centralus" -var resourcegroup="GoCloud" -auto-approve || FAILURES="$FAILURES $TESTDIR" 67 ;; 68 esac 69 popd &> /dev/null 70 71 72 TESTDIR="mysql/gcpmysql" 73 echo 74 echo "***** $TESTDIR *****" 75 pushd "$TESTDIR" &> /dev/null 76 case "$op" in 77 init) 78 terraform init && terraform apply -var project="go-cloud-test-216917" -auto-approve || FAILURES="$FAILURES $TESTDIR" 79 ;; 80 run) 81 go test -mod=readonly -race -json | go run "$rootdir"/internal/testing/test-summary/test-summary.go -progress || FAILURES="$FAILURES $TESTDIR" 82 ;; 83 cleanup) 84 terraform destroy -var project="go-cloud-test-216917" -auto-approve || FAILURES="$FAILURES $TESTDIR" 85 ;; 86 esac 87 popd &> /dev/null 88 89 90 TESTDIR="mysql/awsmysql" 91 echo 92 echo "***** $TESTDIR *****" 93 pushd "$TESTDIR" &> /dev/null 94 case "$op" in 95 init) 96 terraform init && terraform apply -var region="us-west-1" -auto-approve || FAILURES="$FAILURES $TESTDIR" 97 ;; 98 run) 99 go test -mod=readonly -race -json | go run "$rootdir"/internal/testing/test-summary/test-summary.go -progress || FAILURES="$FAILURES $TESTDIR" 100 ;; 101 cleanup) 102 terraform destroy -var region="us-west-1" -auto-approve || FAILURES="$FAILURES $TESTDIR" 103 ;; 104 esac 105 popd &> /dev/null 106 107 108 TESTDIR="postgres/gcppostgres" 109 echo 110 echo "***** $TESTDIR *****" 111 pushd "$TESTDIR" &> /dev/null 112 case "$op" in 113 init) 114 terraform init && terraform apply -var project="go-cloud-test-216917" -auto-approve || FAILURES="$FAILURES $TESTDIR" 115 ;; 116 run) 117 go test -mod=readonly -race -json | go run "$rootdir"/internal/testing/test-summary/test-summary.go -progress || FAILURES="$FAILURES $TESTDIR" 118 ;; 119 cleanup) 120 terraform destroy -var project="go-cloud-test-216917" -auto-approve || FAILURES="$FAILURES $TESTDIR" 121 ;; 122 esac 123 popd &> /dev/null 124 125 126 TESTDIR="postgres/awspostgres" 127 echo 128 echo "***** $TESTDIR *****" 129 pushd "$TESTDIR" &> /dev/null 130 case "$op" in 131 init) 132 terraform init && terraform apply -var region="us-west-1" -auto-approve || FAILURES="$FAILURES $TESTDIR" 133 ;; 134 run) 135 go test -mod=readonly -race -json | go run "$rootdir"/internal/testing/test-summary/test-summary.go -progress || FAILURES="$FAILURES $TESTDIR" 136 ;; 137 cleanup) 138 terraform destroy -var region="us-west-1" -auto-approve || FAILURES="$FAILURES $TESTDIR" 139 ;; 140 esac 141 popd &> /dev/null 142 143 144 # This iterates over all packages that have a "testdata" directory, using that 145 # as a signal for record/replay tests, and runs the tests with a "-record" flag. 146 # This verifies that we can generate a fresh recording against the live service. 147 while read -r TESTDIR; do 148 # Skip some packages that have a testdata/ dir but aren't record/replay. 149 if [ "$TESTDIR" == "./samples/order" ]; then 150 continue; 151 fi 152 echo 153 echo "***** $TESTDIR *****" 154 pushd "$TESTDIR" &> /dev/null 155 case "$op" in 156 init) 157 ;; 158 run|rerecord) 159 go test -mod=readonly -race -record -json | go run "$rootdir"/internal/testing/test-summary/test-summary.go -progress || FAILURES="$FAILURES $TESTDIR" 160 ;; 161 cleanup) 162 ;; 163 esac 164 popd &> /dev/null 165 done < <( find . -name testdata -printf "%h\\n" ) 166 167 echo 168 echo 169 if [ ! -z "$FAILURES" ]; then 170 echo "FAILED!" 171 echo "Investigate and re-run -record tests for the following packages: $FAILURES" 172 exit 1 173 fi 174 175 echo "SUCCESS!"