forked from paketo-buildpacks/jammy-full-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·111 lines (87 loc) · 2.38 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash
set -eu
set -o pipefail
readonly PROG_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly STACK_DIR="$(cd "${PROG_DIR}/.." && pwd)"
readonly OUTPUT_DIR="${STACK_DIR}/build"
# shellcheck source=SCRIPTDIR/.util/tools.sh
source "${PROG_DIR}/.util/tools.sh"
# shellcheck source=SCRIPTDIR/.util/print.sh
source "${PROG_DIR}/.util/print.sh"
function main() {
local clean token
clean="false"
token=""
while [[ "${#}" != 0 ]]; do
case "${1}" in
--help|-h)
shift 1
usage
exit 0
;;
--clean|-c)
shift 1
clean="true"
;;
--token|-t)
token="${2}"
shift 2
;;
"")
# skip if the argument is empty
shift 1
;;
*)
util::print::error "unknown argument \"${1}\""
esac
done
tools::install "${token}"
if [[ "${clean}" == "true" ]]; then
util::print::title "Cleaning up preexisting stack archives..."
rm -rf "${OUTPUT_DIR}"
fi
if ! [[ -f "${OUTPUT_DIR}/build.oci" ]] || ! [[ -f "${OUTPUT_DIR}/run.oci" ]]; then
util::print::title "Creating stack..."
"${STACK_DIR}/scripts/create.sh"
fi
tests::run
}
function usage() {
cat <<-USAGE
test.sh [OPTIONS]
Runs acceptance tests against the stack. Uses the OCI images
${STACK_DIR}/build/build.oci
and
${STACK_DIR}/build/run.oci
if they exist. Otherwise, first runs create.sh to create them.
OPTIONS
--clean -c clears contents of stack output directory before running tests
--token <token> Token used to download assets from GitHub (e.g. jam, pack, etc) (optional)
--help -h prints the command usage
USAGE
}
function tools::install() {
local token
token="${1}"
util::tools::jam::install \
--directory "${STACK_DIR}/.bin" \
--token "${token}"
util::tools::pack::install \
--directory "${STACK_DIR}/.bin" \
--token "${token}"
util::tools::skopeo::check
}
function tests::run() {
util::print::title "Run Stack Acceptance Tests"
export CGO_ENABLED=0
testout=$(mktemp)
pushd "${STACK_DIR}" > /dev/null
if GOMAXPROCS="${GOMAXPROCS:-4}" go test -count=1 -timeout 0 ./... -v -run Acceptance | tee "${testout}"; then
util::tools::tests::checkfocus "${testout}"
util::print::success "** GO Test Succeeded **"
else
util::print::error "** GO Test Failed **"
fi
popd > /dev/null
}
main "${@:-}"