Skip to content

Commit 5dc7b57

Browse files
committed
test(scripts): add JAVA_OPTS tokenization smoke test to source-path script
1 parent 453dc44 commit 5dc7b57

1 file changed

Lines changed: 40 additions & 6 deletions

File tree

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/bash
22
# Manual smoke test for the bin/finalize source/git buildpack path.
33
# Simulates what bin/finalize does: build javaexec into a temp dir and pass
4-
# the path via JAVAEXEC_BINARY_PATH. Verifies the binary builds and that
5-
# InstallJavaexecLauncher picks up the override (unit tests cover the logic;
6-
# this confirms the wiring end-to-end on this machine).
4+
# the path via JAVAEXEC_BINARY_PATH. Verifies the binary builds, that
5+
# InstallJavaexecLauncher picks up the override, and that javaexec tokenizes
6+
# JAVA_OPTS correctly when actually invoked.
77
set -euo pipefail
88

99
BUILDPACK_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
@@ -12,19 +12,53 @@ cd "$BUILDPACK_DIR"
1212
tmpdir=$(mktemp -d)
1313
trap 'rm -rf "$tmpdir"' EXIT
1414

15-
echo "==> [1/3] Build javaexec from source (as bin/finalize now does)"
15+
echo "==> [1/4] Build javaexec from source (as bin/finalize now does)"
1616
go build -mod=vendor -o "$tmpdir/javaexec" ./src/java/javaexec/cli
1717
echo " OK: $tmpdir/javaexec ($(wc -c < "$tmpdir/javaexec") bytes)"
1818

1919
echo ""
20-
echo "==> [2/3] Build finalize from source"
20+
echo "==> [2/4] Build finalize from source"
2121
go build -mod=vendor -o "$tmpdir/finalize" ./src/java/finalize/cli
2222
echo " OK: $tmpdir/finalize"
2323

2424
echo ""
25-
echo "==> [3/3] Unit tests: InstallJavaexecLauncher with JAVAEXEC_BINARY_PATH override"
25+
echo "==> [3/4] Unit tests: InstallJavaexecLauncher with JAVAEXEC_BINARY_PATH override"
2626
go test ./src/java/finalize/ -count=1 -v -run "javaexec launcher" 2>&1 | grep -E "PASS|FAIL|RUN|---"
2727

28+
echo ""
29+
echo "==> [4/4] Tokenization smoke test: run javaexec with a fake java binary"
30+
31+
# Fake java: prints each received argument on its own line.
32+
cat > "$tmpdir/fake-java" << 'EOF'
33+
#!/bin/bash
34+
printf '%s\n' "$@"
35+
EOF
36+
chmod +x "$tmpdir/fake-java"
37+
38+
# Quoted value with spaces → one token; cron expr with * → literal; $(...) → not executed.
39+
JAVA_OPTS='-Dfoo="bar baz" -DcronSched="0 */7 * * * *" -Dwhere=$(hostname)' \
40+
"$tmpdir/javaexec" "$tmpdir/fake-java" -jar app.jar 2>/dev/null > "$tmpdir/actual.txt"
41+
42+
expected="-Dfoo=bar baz
43+
-DcronSched=0 */7 * * * *
44+
-Dwhere=\$(hostname)
45+
-jar
46+
app.jar"
47+
48+
actual=$(cat "$tmpdir/actual.txt")
49+
50+
if [ "$actual" = "$expected" ]; then
51+
echo " OK: all tokens correct"
52+
else
53+
echo " FAIL: unexpected output"
54+
echo " expected:"
55+
printf '%s\n' "$expected" | sed 's/^/ /'
56+
echo " got:"
57+
printf '%s\n' "$actual" | sed 's/^/ /'
58+
exit 1
59+
fi
60+
2861
echo ""
2962
echo "PASS: source/git buildpack path works."
3063
echo " bin/finalize builds javaexec and passes it via JAVAEXEC_BINARY_PATH."
64+
echo " javaexec tokenizes JAVA_OPTS correctly without shell execution."

0 commit comments

Comments
 (0)