github.com/graywolf-at-work-2/terraform-vendor@v1.4.5/internal/command/e2etest/make-archive.sh (about) 1 #!/bin/bash 2 3 # For normal use this package can just be tested with "go test" as standard, 4 # but this script is an alternative to allow the tests to be run somewhere 5 # other than where they are built. 6 7 # The primary use for this is cross-compilation, where e.g. we can produce an 8 # archive that can be extracted on a Windows system to run the e2e tests there: 9 # $ GOOS=windows GOARCH=amd64 ./make-archive.sh 10 # 11 # This will produce a zip file build/terraform-e2etest_windows_amd64.zip which 12 # can be shipped off to a Windows amd64 system, extracted to some directory, 13 # and then executed as follows: 14 # set TF_ACC=1 15 # ./e2etest.exe 16 # 17 # Because separated e2etest harnesses are intended for testing against "real" 18 # release executables, the generated archives don't include a copy of 19 # the Terraform executable. Instead, the caller of the tests must retrieve 20 # and extract a release package into the working directory before running 21 # the e2etest executable, so that "e2etest" can find and execute it. 22 23 set +euo pipefail 24 25 # Always run from the directory where this script lives 26 cd "$( dirname "${BASH_SOURCE[0]}" )" 27 28 GOOS="$(go env GOOS)" 29 GOARCH="$(go env GOARCH)" 30 GOEXE="$(go env GOEXE)" 31 OUTDIR="build/${GOOS}_${GOARCH}" 32 OUTFILE="terraform-e2etest_${GOOS}_${GOARCH}.zip" 33 34 LDFLAGS="-X github.com/hashicorp/terraform/internal/command/e2etest.terraformBin=./terraform$GOEXE" 35 # Caller may pass in the environment variable GO_LDFLAGS with additional 36 # flags we'll use when building. 37 if [ -n "${GO_LDFLAGS+set}" ]; then 38 LDFLAGS="${GO_LDFLAGS} ${LDFLAGS}" 39 fi 40 41 mkdir -p "$OUTDIR" 42 43 # We need the test fixtures available when we run the tests. 44 cp -r testdata "$OUTDIR/testdata" 45 46 # Build the test program 47 go test -o "$OUTDIR/e2etest$GOEXE" -c -ldflags "$LDFLAGS" github.com/hashicorp/terraform/internal/command/e2etest 48 49 # Now bundle it all together for easy shipping! 50 cd "$OUTDIR" 51 zip -r "../$OUTFILE" * 52 53 echo "e2etest archive created at build/$OUTFILE"