2017-07-07 20:46:24 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# For normal use this package can just be tested with "go test" as standard,
|
|
|
|
# but this script is an alternative to allow the tests to be run somewhere
|
|
|
|
# other than where they are built.
|
|
|
|
|
|
|
|
# The primary use for this is cross-compilation, where e.g. we can produce an
|
|
|
|
# archive that can be extracted on a Windows system to run the e2e tests there:
|
|
|
|
# $ GOOS=windows GOARCH=amd64 ./make-archive.sh
|
|
|
|
#
|
|
|
|
# This will produce a zip file build/terraform-s2stest_windows_amd64.zip which
|
|
|
|
# can be shipped off to a Windows amd64 system, extracted to some directory,
|
|
|
|
# and then executed as follows:
|
|
|
|
# set TF_ACC=1
|
|
|
|
# ./e2etest.exe
|
2021-12-23 11:10:59 -06:00
|
|
|
#
|
|
|
|
# Because separated e2etest harnesses are intended for testing against "real"
|
|
|
|
# release executables, the generated archives don't include a copy of
|
|
|
|
# the Terraform executable. Instead, the caller of the tests must retrieve
|
|
|
|
# and extract a release package into the working directory before running
|
|
|
|
# the e2etest executable, so that "e2etest" can find and execute it.
|
2017-07-07 20:46:24 -05:00
|
|
|
|
|
|
|
set +euo pipefail
|
|
|
|
|
|
|
|
# Always run from the directory where this script lives
|
|
|
|
cd "$( dirname "${BASH_SOURCE[0]}" )"
|
|
|
|
|
|
|
|
GOOS="$(go env GOOS)"
|
|
|
|
GOARCH="$(go env GOARCH)"
|
|
|
|
GOEXE="$(go env GOEXE)"
|
|
|
|
OUTDIR="build/${GOOS}_${GOARCH}"
|
|
|
|
OUTFILE="terraform-e2etest_${GOOS}_${GOARCH}.zip"
|
|
|
|
|
2022-05-19 14:05:22 -05:00
|
|
|
LDFLAGS="-X github.com/hashicorp/terraform/internal/command/e2etest.terraformBin=./terraform$GOEXE"
|
|
|
|
# Caller may pass in the environment variable GO_LDFLAGS with additional
|
|
|
|
# flags we'll use when building.
|
|
|
|
if [ -n "${GO_LDFLAGS+set}" ]; then
|
|
|
|
LDFLAGS="${GO_LDFLAGS} ${LDFLAGS}"
|
|
|
|
fi
|
|
|
|
|
2017-07-07 20:46:24 -05:00
|
|
|
mkdir -p "$OUTDIR"
|
|
|
|
|
|
|
|
# We need the test fixtures available when we run the tests.
|
2019-06-30 02:38:36 -05:00
|
|
|
cp -r testdata "$OUTDIR/testdata"
|
2017-07-07 20:46:24 -05:00
|
|
|
|
|
|
|
# Build the test program
|
2022-05-19 14:05:22 -05:00
|
|
|
go test -o "$OUTDIR/e2etest$GOEXE" -c -ldflags "$LDFLAGS" github.com/hashicorp/terraform/internal/command/e2etest
|
2017-07-07 20:46:24 -05:00
|
|
|
|
|
|
|
# Now bundle it all together for easy shipping!
|
|
|
|
cd "$OUTDIR"
|
|
|
|
zip -r "../$OUTFILE" *
|
|
|
|
|
|
|
|
echo "e2etest archive created at build/$OUTFILE"
|