This directory contains the test suite for tile-diff, organized into unit tests, integration tests, and acceptance tests.
test/
├── acceptance_suite_test.go # Ginkgo test suite bootstrap
├── acceptance_test.go # Pivnet integration acceptance tests
├── acceptance_helpers_test.go # Shared helper functions for tests
├── comparison_test.go # Unit tests for comparison logic
├── enrichment_test.go # Unit tests for enrichment logic
├── integration_test.go # Integration tests with real tile files
└── fixtures/ # Test fixtures and sample dataUnit tests validate individual packages and components in isolation:
- Location:
./pkg/*/...(within each package) - Framework: Standard Go testing
- Coverage: Metadata extraction, comparison logic, report generation
- Run with:
make testorgo test -v ./pkg/... - Dependencies: None - uses mock data and fixtures
Example:
# Run all unit tests with coverage
make test
# Run tests for specific package
go test -v ./pkg/compare/
go test -v ./pkg/metadata/Integration tests verify functionality using real tile files:
- Location:
test/integration_test.go,test/comparison_test.go - Framework: Standard Go testing with build tags
- Coverage: Real tile metadata extraction, full comparison workflows
- Run with:
go test -v -tags=integration ./test/... - Dependencies: Requires actual
.pivotaltile files
Example:
# Run integration tests (requires tile files in /tmp/elastic-runtime/)
go test -v -tags=integration ./test/...Modern acceptance tests using Ginkgo v2 BDD framework:
- Location:
test/acceptance_test.go - Framework: Ginkgo v2 + Gomega
- Coverage: End-to-end Pivnet integration, caching, EULA handling, error scenarios
- Run with:
make acceptance-testorginkgo -v ./test - Dependencies: Requires
PIVNET_TOKENenvironment variable
Test Suites:
- Non-Interactive Mode - Downloads, version matching, output formats
- Cache Verification - Tile caching and reuse behavior
- EULA Handling - EULA acceptance and persistence
- Error Handling - Invalid tokens, ambiguous products, mixed modes
- Local Files Mode - Backward compatibility with local tiles
Example:
# Set Pivnet token
export PIVNET_TOKEN="your-pivnet-api-token"
# Run all acceptance tests
make acceptance-test
# Or run fast tests only (skips slow downloads)
make acceptance-test-fast-with-token PIVNET_TOKEN=your-token
# Run specific test suite
ginkgo -v --focus="Cache Verification" ./test
# Run with debugging output
ginkgo -v -trace ./test
# Skip slow tests using labels
ginkgo -v --label-filter='!slow' ./testPIVNET_TOKEN- Required for acceptance tests that download from PivnetENABLE_DOWNLOAD_TESTS- Set to1to enable expensive download tests (⚠️ downloads multi-GB files)TILE_DIFF_BIN- Path to tile-diff binary (default:./tile-diff)TEST_CACHE_DIR- Cache directory for test runs (default:/tmp/tile-diff-test-cache)
- ISP bandwidth quota consumption
- CI/CD pipeline slowdowns
- Expensive Pivnet API usage
Only enable when specifically testing download functionality:
export ENABLE_DOWNLOAD_TESTS=1
make acceptance-testThe acceptance_helpers_test.go file provides shared utilities:
runTileDiff(args...)- Execute tile-diff binary with test configurationsetupCacheDir()- Create clean test cache directorycleanupCacheDir()- Remove test cache directorytileExistsInCache(filename)- Check if tile is cached
# 1. Build the binary
make build
# 2. Run unit tests
make test
# 3. Run acceptance tests (with Pivnet token)
export PIVNET_TOKEN="your-token"
make acceptance-test
# 4. Run all tests
make test-allFor CI environments, use non-interactive mode and pre-accepted EULAs:
# Set token from secrets
export PIVNET_TOKEN="${CI_PIVNET_TOKEN}"
# Run unit tests (always)
make test
# Run acceptance tests (if token available)
if [ -n "$PIVNET_TOKEN" ]; then
make acceptance-test
fiThe fixtures/ directory contains sample data for tests:
- Sample tile metadata
- Mock API responses
- Example configuration files
var _ = Describe("Feature Name", func() {
BeforeEach(func() {
// Setup for each test
setupCacheDir()
})
AfterEach(func() {
// Cleanup after each test
cleanupCacheDir()
})
Context("Specific Scenario", func() {
It("describes expected behavior", func() {
output, err := runTileDiff(args...)
Expect(err).NotTo(HaveOccurred())
Expect(output).To(ContainSubstring("expected"))
})
})
})Acceptance tests use live Pivnet data and may require updates:
// NOTE: These tests use p-redis 3.2.0 -> 3.2.1 as examples.
// If these specific versions are no longer available in Pivnet, the tests
// will fail. This is expected behavior - update the product-slug and
// versions as needed to match available releases.If tests fail due to missing product versions:
- Check Pivnet for available versions
- Update test to use available product/versions
- Update --product-file flag if product has multiple files
- Document the change in test comments
Tests are automatically skipped when dependencies are missing:
if os.Getenv("PIVNET_TOKEN") == "" {
Skip("PIVNET_TOKEN not set - skipping live Pivnet tests")
}Generate coverage reports:
# Generate coverage for unit tests
make test-coverage
# Open HTML coverage report
open coverage.html
# View coverage in terminal
go tool cover -func=coverage.txt# Ginkgo verbose mode
ginkgo -v ./test
# With trace for debugging
ginkgo -v -trace ./test
# Standard go test verbose
go test -v ./pkg/...# Ginkgo focus on specific test
ginkgo --focus="downloads tiles with exact versions" ./test
# Standard go test
go test -v -run TestMetadataExtraction ./pkg/metadata/By default, tests clean up their cache. To preserve for debugging:
# Comment out cleanupCacheDir() in AfterEach
# Or manually inspect: ls -la /tmp/tile-diff-test-cache/- Unit tests should be fast - Use mocks and fixtures, no external dependencies
- Integration tests verify real behavior - Use actual tile files when available
- Acceptance tests validate user workflows - Test complete scenarios end-to-end
- Clean up test artifacts - Use BeforeEach/AfterEach for setup/teardown
- Handle missing dependencies gracefully - Skip tests rather than fail
- Document test data assumptions - Note when tests rely on specific Pivnet versions
- Use descriptive test names - Focus on behavior, not implementation
Acceptance tests require a Pivnet token:
export PIVNET_TOKEN="your-pivnet-api-token"Build the binary first:
make buildTest product/version no longer available in Pivnet - update test to use available versions.
Integration tests need actual tile files:
# Download tiles manually or use tile-diff to cache them
./tile-diff --product-slug cf --old-version 6.0.22 --new-version 10.2.5When adding new tests:
- Unit tests - Add to relevant package in
pkg/*/ - Ginkgo acceptance tests - Add to
test/acceptance_test.go - Integration tests - Add to
test/integration_test.gowith// +build integrationtag - Test helpers - Add shared utilities to
test/acceptance_helpers_test.go - Update documentation - Keep this README current with test changes
Run the full test suite before submitting:
make test-all