Skip to content

Commit 67e94b4

Browse files
committed
Add Switchblade integration tests for Java buildpack
Implement Go-based integration tests using Cloud Foundry Switchblade framework to replace external system tests with in-repo testing infrastructure. Tests cover: - Tomcat container with JRE selection (Java 8, 11, 17) - Spring Boot applications with auto-reconfiguration and Java CFEnv - Java Main applications with custom arguments and JAVA_OPTS - Offline/cached buildpack mode - Memory calculator configuration The test suite supports both Cloud Foundry and Docker platforms and runs in parallel for improved test execution time. Test Results: - All 13 integration tests passing - Average execution time: ~54 seconds (parallel execution) - Validates buildpack behavior with actual deployments Files Added: - src/integration/*_test.go - Test implementations - src/integration/init_test.go - Test suite initialization - src/integration/README.md - Documentation - scripts/integration.sh - Test runner script - go.mod, go.sum - Go dependencies
1 parent de6e09d commit 67e94b4

File tree

9 files changed

+4057
-0
lines changed

9 files changed

+4057
-0
lines changed

go.mod

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
module github.com/cloudfoundry/java-buildpack
2+
3+
go 1.25.4
4+
5+
require (
6+
github.com/cloudfoundry/switchblade v0.9.0
7+
github.com/onsi/gomega v1.38.2
8+
github.com/sclevine/spec v1.4.0
9+
)
10+
11+
require (
12+
github.com/Microsoft/go-winio v0.6.0 // indirect
13+
github.com/docker/distribution v2.8.1+incompatible // indirect
14+
github.com/docker/docker v24.0.9+incompatible // indirect
15+
github.com/docker/go-connections v0.4.0 // indirect
16+
github.com/docker/go-units v0.5.0 // indirect
17+
github.com/gabriel-vasile/mimetype v1.4.6 // indirect
18+
github.com/gogo/protobuf v1.3.2 // indirect
19+
github.com/google/go-cmp v0.7.0 // indirect
20+
github.com/opencontainers/go-digest v1.0.0 // indirect
21+
github.com/opencontainers/image-spec v1.1.0 // indirect
22+
github.com/paketo-buildpacks/packit/v2 v2.16.0 // indirect
23+
github.com/pkg/errors v0.9.1 // indirect
24+
github.com/teris-io/shortid v0.0.0-20220617161101-71ec9f2aa569 // indirect
25+
github.com/ulikunitz/xz v0.5.12 // indirect
26+
go.yaml.in/yaml/v3 v3.0.4 // indirect
27+
golang.org/x/mod v0.27.0 // indirect
28+
golang.org/x/net v0.43.0 // indirect
29+
golang.org/x/sync v0.16.0 // indirect
30+
golang.org/x/sys v0.35.0 // indirect
31+
golang.org/x/text v0.28.0 // indirect
32+
golang.org/x/tools v0.36.0 // indirect
33+
)

go.sum

Lines changed: 3193 additions & 0 deletions
Large diffs are not rendered by default.

scripts/integration.sh

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# Script to run integration tests using Switchblade framework
6+
# Supports both Cloud Foundry and Docker platforms
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
10+
SRC_DIR="${ROOT_DIR}/src/integration"
11+
12+
# Default configuration
13+
PLATFORM="${PLATFORM:-cf}"
14+
STACK="${STACK:-cflinuxfs4}"
15+
CACHED="${CACHED:-false}"
16+
GITHUB_TOKEN="${GITHUB_TOKEN:-}"
17+
18+
# Color output
19+
RED='\033[0;31m'
20+
GREEN='\033[0;32m'
21+
YELLOW='\033[1;33m'
22+
NC='\033[0m' # No Color
23+
24+
function print_usage() {
25+
echo "Usage: $0 [OPTIONS]"
26+
echo ""
27+
echo "Run integration tests for the Java buildpack using Switchblade"
28+
echo ""
29+
echo "Options:"
30+
echo " -p, --platform PLATFORM Platform to test against (cf or docker, default: cf)"
31+
echo " -s, --stack STACK Stack to use (default: cflinuxfs4)"
32+
echo " -c, --cached Run cached/offline tests"
33+
echo " -t, --github-token TOKEN GitHub API token for rate limiting"
34+
echo " -h, --help Show this help message"
35+
echo ""
36+
echo "Environment Variables:"
37+
echo " BUILDPACK_FILE Path to buildpack zip file (required)"
38+
echo " PLATFORM Platform to test (cf or docker)"
39+
echo " STACK Stack to use for tests"
40+
echo " CACHED Run cached tests (true/false)"
41+
echo " GITHUB_TOKEN GitHub API token"
42+
echo ""
43+
echo "Examples:"
44+
echo " # Test on Cloud Foundry with cflinuxfs4"
45+
echo " BUILDPACK_FILE=/tmp/buildpack.zip $0"
46+
echo ""
47+
echo " # Test on Docker"
48+
echo " BUILDPACK_FILE=/tmp/buildpack.zip $0 --platform docker"
49+
echo ""
50+
echo " # Run cached/offline tests"
51+
echo " BUILDPACK_FILE=/tmp/buildpack.zip $0 --cached"
52+
}
53+
54+
# Parse command-line arguments
55+
while [[ $# -gt 0 ]]; do
56+
case $1 in
57+
-p|--platform)
58+
PLATFORM="$2"
59+
shift 2
60+
;;
61+
-s|--stack)
62+
STACK="$2"
63+
shift 2
64+
;;
65+
-c|--cached)
66+
CACHED="true"
67+
shift
68+
;;
69+
-t|--github-token)
70+
GITHUB_TOKEN="$2"
71+
shift 2
72+
;;
73+
-h|--help)
74+
print_usage
75+
exit 0
76+
;;
77+
*)
78+
echo "Unknown option: $1"
79+
print_usage
80+
exit 1
81+
;;
82+
esac
83+
done
84+
85+
# Validate required environment variables
86+
if [[ -z "${BUILDPACK_FILE:-}" ]]; then
87+
echo -e "${RED}ERROR: BUILDPACK_FILE environment variable is required${NC}"
88+
echo ""
89+
print_usage
90+
exit 1
91+
fi
92+
93+
if [[ ! -f "${BUILDPACK_FILE}" ]]; then
94+
echo -e "${RED}ERROR: Buildpack file not found: ${BUILDPACK_FILE}${NC}"
95+
exit 1
96+
fi
97+
98+
# Print configuration
99+
echo -e "${GREEN}=== Java Buildpack Integration Tests ===${NC}"
100+
echo "Platform: ${PLATFORM}"
101+
echo "Stack: ${STACK}"
102+
echo "Cached Tests: ${CACHED}"
103+
echo "Buildpack: ${BUILDPACK_FILE}"
104+
echo ""
105+
106+
# Check dependencies
107+
if ! command -v go &> /dev/null; then
108+
echo -e "${RED}ERROR: Go is not installed${NC}"
109+
exit 1
110+
fi
111+
112+
echo -e "${YELLOW}Installing Go dependencies...${NC}"
113+
cd "${ROOT_DIR}"
114+
go mod download
115+
116+
# Build test flags
117+
TEST_FLAGS="-v"
118+
TEST_FLAGS="${TEST_FLAGS} -platform=${PLATFORM}"
119+
TEST_FLAGS="${TEST_FLAGS} -stack=${STACK}"
120+
121+
if [[ "${CACHED}" == "true" ]]; then
122+
TEST_FLAGS="${TEST_FLAGS} -cached"
123+
fi
124+
125+
if [[ -n "${GITHUB_TOKEN}" ]]; then
126+
TEST_FLAGS="${TEST_FLAGS} -github-token=${GITHUB_TOKEN}"
127+
fi
128+
129+
# Run tests
130+
echo -e "${YELLOW}Running integration tests...${NC}"
131+
echo ""
132+
133+
cd "${SRC_DIR}"
134+
135+
if go test ${TEST_FLAGS} -timeout 30m ./...; then
136+
echo ""
137+
echo -e "${GREEN}✓ All integration tests passed!${NC}"
138+
exit 0
139+
else
140+
echo ""
141+
echo -e "${RED}✗ Integration tests failed${NC}"
142+
exit 1
143+
fi

0 commit comments

Comments
 (0)