This directory contains integration tests for the Java buildpack using the Switchblade framework.
Switchblade is a Go-based integration testing framework that supports both Cloud Foundry and Docker platforms. This allows us to write tests once and run them on either platform.
- Go 1.25 or later
- Cloud Foundry CLI (if testing on CF)
- Docker (if testing on Docker)
- A packaged buildpack zip file
- GitHub Personal Access Token (required for Docker platform tests)
- Create token at: https://github.com/settings/tokens
- Requires
public_repoorreposcope - Used to query buildpack metadata from GitHub API
First, create a buildpack zip file:
bundle exec rake packageThis will create a file like java-buildpack-v4.x.x.zip in the project root.
Use the provided script to run the tests:
# Test on Cloud Foundry (default)
BUILDPACK_FILE=/path/to/java-buildpack-v4.x.x.zip ./scripts/integration.sh
# Test on Docker (requires GitHub token)
BUILDPACK_FILE=/path/to/java-buildpack-v4.x.x.zip \
GITHUB_TOKEN=your_github_token_here \
./scripts/integration.sh --platform docker
# Run cached/offline tests
BUILDPACK_FILE=/path/to/java-buildpack-v4.x.x.zip ./scripts/integration.sh --cached
# Specify a different stack
BUILDPACK_FILE=/path/to/java-buildpack-v4.x.x.zip ./scripts/integration.sh --stack cflinuxfs4You can also run the tests directly using Go:
cd src/integration
# Run all tests
BUILDPACK_FILE=/path/to/buildpack.zip go test -v -timeout 30m
# Run specific test suite
BUILDPACK_FILE=/path/to/buildpack.zip go test -v -run TestIntegration/Tomcat
# Run on Docker
BUILDPACK_FILE=/path/to/buildpack.zip go test -v -platform=docker
# Run offline tests
BUILDPACK_FILE=/path/to/buildpack.zip go test -v -cachedinit_test.go- Test suite initialization and configurationtomcat_test.go- Tomcat container testsspring_boot_test.go- Spring Boot application testsjava_main_test.go- Java Main class application testsoffline_test.go- Offline/cached buildpack tests
Tests use fixtures from the spec/fixtures directory. The main fixture for integration tests is:
integration_valid- A simple Java application with a Main-Class
BUILDPACK_FILE(required) - Path to the packaged buildpack zip filePLATFORM- Platform to test against:cf(default) ordockerSTACK- Stack to use for tests (default:cflinuxfs4)CACHED- Run offline/cached tests (default:false)GITHUB_TOKEN- GitHub API token to avoid rate limiting
-platform- Platform type (cfordocker)-stack- Stack name (e.g.,cflinuxfs4)-cached- Enable offline tests-github-token- GitHub API token-serial- Run tests serially instead of in parallel
The integration tests cover:
-
Container Types
- Tomcat container with WAR files
- Spring Boot executable JARs
- Java Main applications
-
JRE Selection
- Java 8, 11, 17 runtime selection
- Multiple JRE vendors (OpenJDK, Zulu, etc.)
-
Configuration
- Memory calculator settings
- Custom JAVA_OPTS
- Framework-specific configuration
-
Offline Mode
- Cached buildpack deployment
- No internet access scenarios
To add a new test:
- Create a new test file in
src/integration/(e.g.,myfeature_test.go) - Define a test function that returns
func(*testing.T, spec.G, spec.S):func testMyFeature(platform switchblade.Platform, fixtures string) func(*testing.T, spec.G, spec.S) { return func(t *testing.T, context spec.G, it spec.S) { // Your tests here } }
- Register the test in
init_test.go:suite("MyFeature", testMyFeature(platform, fixtures))
To integrate with CI/CD pipelines:
# Example GitHub Actions
- name: Run Integration Tests
env:
BUILDPACK_FILE: ${{ github.workspace }}/java-buildpack.zip
CF_API: ${{ secrets.CF_API }}
CF_USERNAME: ${{ secrets.CF_USERNAME }}
CF_PASSWORD: ${{ secrets.CF_PASSWORD }}
run: |
./scripts/integration.sh --platform cfThe previous integration tests were:
- Located in a separate repository (
java-buildpack-system-test) - Written in Java with JUnit
- Only supported Cloud Foundry
- Required extensive configuration
The new Switchblade-based tests:
- Are co-located with the buildpack code
- Written in Go with Gomega matchers
- Support both Cloud Foundry and Docker
- Have simpler configuration and setup
go mod tidy
go mod downloadEnsure the BUILDPACK_FILE environment variable points to a valid zip file:
ls -lh $BUILDPACK_FILEEnsure you're logged into Cloud Foundry:
cf login -a <api-endpoint>Ensure Docker is running and you have permission to use it:
docker psIf you see errors like "Bad credentials" or "401 Unauthorized" when running Docker platform tests:
failed to build buildpacks: failed to list buildpacks: received unexpected response status: HTTP/2.0 401 Unauthorized
This means you need to provide a GitHub Personal Access Token:
- Create a token at https://github.com/settings/tokens
- Grant it
public_repoorreposcope - Export it as an environment variable:
export GITHUB_TOKEN=your_token_here BUILDPACK_FILE=/path/to/buildpack.zip ./scripts/integration.sh --platform docker
Alternatively, pass it via the command line:
BUILDPACK_FILE=/path/to/buildpack.zip ./scripts/integration.sh --platform docker --github-token your_token_here