github.com/hooklift/terraform@v0.11.0-beta1.0.20171117000744-6786c1361ffe/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-s2stest_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 # Since the test archive includes both the test fixtures and the compiled 17 # terraform executable along with this test program, the result is 18 # self-contained and does not require a local Go compiler on the target system. 19 20 set +euo pipefail 21 22 # Always run from the directory where this script lives 23 cd "$( dirname "${BASH_SOURCE[0]}" )" 24 25 GOOS="$(go env GOOS)" 26 GOARCH="$(go env GOARCH)" 27 GOEXE="$(go env GOEXE)" 28 OUTDIR="build/${GOOS}_${GOARCH}" 29 OUTFILE="terraform-e2etest_${GOOS}_${GOARCH}.zip" 30 31 mkdir -p "$OUTDIR" 32 33 # We need the test fixtures available when we run the tests. 34 cp -r test-fixtures "$OUTDIR/test-fixtures" 35 36 # Bundle a copy of our binary so the target system doesn't need the go 37 # compiler installed. 38 go build -o "$OUTDIR/terraform$GOEXE" github.com/hashicorp/terraform 39 40 # Build the test program 41 go test -o "$OUTDIR/e2etest$GOEXE" -c -ldflags "-X github.com/hashicorp/terraform/command/e2etest.terraformBin=./terraform$GOEXE" github.com/hashicorp/terraform/command/e2etest 42 43 # Now bundle it all together for easy shipping! 44 cd "$OUTDIR" 45 zip -r "../$OUTFILE" * 46 47 echo "e2etest archive created at build/$OUTFILE"