Skip to content

test(integration): add integration tests for Docker export to cache#249

Merged
leodido merged 7 commits intomainfrom
leo/integration-tests
Oct 24, 2025
Merged

test(integration): add integration tests for Docker export to cache#249
leodido merged 7 commits intomainfrom
leo/integration-tests

Conversation

@leodido
Copy link
Contributor

@leodido leodido commented Oct 2, 2025

Add Integration Tests for Docker Export to Cache

Description

This PR adds comprehensive integration tests for the Docker image export to cache functionality introduced in the previous PR. These tests verify the complete end-to-end behavior of the feature across different configuration methods and scenarios.

What's Tested:

  1. Default Behavior: Verifies that Docker images are NOT exported to cache by default (backward compatibility)
  2. Package Config: Tests enabling export via exportToCache: true in BUILD.yaml
  3. CLI Flag Override: Tests --docker-export-to-cache flag overriding package config in both directions
  4. Environment Variable: Tests LEEWAY_DOCKER_EXPORT_TO_CACHE environment variable
  5. Metadata Extraction: Verifies correct metadata extraction from exported Docker images
  6. Cache Structure: Validates the cache artifact structure and content

Test Coverage:

  • All configuration precedence levels (env var > CLI flag > package config > default)
  • Cache artifact creation and structure validation
  • Metadata file generation and content verification
  • Image digest extraction and validation
  • Docker image load and execution verification
  • Backward compatibility (no export by default, push)

Related Issue(s)

Fixes https://linear.app/ona-team/issue/CLC-1958/leeway-security-testing-suite
Fixes https://linear.app/ona-team/issue/CLC-2009/docker-export-mode-for-slsa-l3-compliance-leeway

Depends on: #248

How to test

Run the integration tests:

# Run specific test suites
go test -v -tags=integration ./pkg/leeway -run TestDockerPackage_ExportToCache_Integration
go test -v -tags=integration ./pkg/leeway -run TestDockerPackage_CacheRoundTrip_Integration

# Run specific test scenarios
go test -v -tags=integration ./pkg/leeway -run "TestDockerPackage_ExportToCache_Integration/new_export_behavior"
go test -v -tags=integration ./pkg/leeway -run "TestDockerPackage_ExportToCache_Integration/export_without_image_config"

Expected Results:

TestDockerPackage_ExportToCache_Integration (3 subtests):

  • legacy_push_behavior - Validates legacy push workflow (expected to fail at push)
  • new_export_behavior - Validates export-to-cache functionality
  • export_without_image_config - Validates export without image tags

TestDockerPackage_CacheRoundTrip_Integration:

  • Builds image with export mode
  • Verifies cache artifact structure
  • Extracts and validates metadata
  • Loads image from tar
  • Verifies image digest matches
  • Runs container to verify functionality

Documentation

No additional documentation needed - these are integration tests that complement the existing unit tests and documentation from the previous PR.

Checklist

  • Integration tests added
  • Tests cover all configuration methods
  • Tests verify cache artifact structure
  • Tests verify metadata extraction
  • Backward compatibility verified
  • All tests pass locally

@leodido leodido self-assigned this Oct 2, 2025
@leodido leodido requested review from aledbf, csweichel and geropl October 2, 2025 16:10
Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

@leodido leodido force-pushed the leo/export-to-cache-images branch 2 times, most recently from 7234cf8 to 4157731 Compare October 24, 2025 12:52
@leodido leodido changed the base branch from leo/export-to-cache-images to main October 24, 2025 13:12
@leodido leodido force-pushed the leo/integration-tests branch 2 times, most recently from edfe7d4 to 204cd66 Compare October 24, 2025 13:18
- Add comprehensive integration tests for exportToCache functionality
- Test default behavior (no export)
- Test export via package config
- Test CLI flag override (both directions)
- Test environment variable
- Test metadata extraction from exported images
- Verify cache artifact structure and content

Co-authored-by: Ona <no-reply@ona.com>
@leodido leodido force-pushed the leo/integration-tests branch from 204cd66 to 43f6e96 Compare October 24, 2025 13:21
leodido and others added 6 commits October 24, 2025 13:31
- Use proper BUILD.yaml in component directories instead of inline components
- Fix package references from :app to app:docker
- Create app/ subdirectory for component files
- Follows leeway workspace conventions

Co-authored-by: Ona <no-reply@ona.com>
- Skip legacy push behavior test (requires Docker Hub credentials)
- Improve file path matching to handle ./ prefix variations
- Normalize paths before comparison (./content vs content)
- Add skipReason field to test cases

Co-authored-by: Ona <no-reply@ona.com>
- Change from skip to expectError for legacy push test
- Validates that legacy push workflow executes (even if push fails)
- Ensures we didn't break existing push behavior
- Test passes if build fails at push step (expected without credentials)
- Export tests continue to validate new functionality

Co-authored-by: Ona <no-reply@ona.com>
- Add expectErrorMatch field with regex pattern matching
- Validate that legacy push fails with Docker Hub auth error
- Ensures test fails for the right reason (missing credentials)
- Makes test more precise and maintainable
- Pattern matches: 'push access denied', 'authorization failed', or 'insufficient_scope'

Co-authored-by: Ona <no-reply@ona.com>
- Change pattern from Docker-specific errors to generic 'build failed'
- Build() wraps detailed Docker errors in generic error message
- Detailed errors (push access denied, authorization failed) are in logs
- Add comment explaining why we can't check specific Docker error
- Test still validates legacy push workflow executes and fails appropriately

Co-authored-by: Ona <no-reply@ona.com>
- docker save stores image with version hash name
- docker load restores with original name, not the desired tag
- Add docker tag step to apply expected image name
- Fixes image inspection failure in round-trip test

Co-authored-by: Ona <no-reply@ona.com>
@leodido leodido merged commit a38f96c into main Oct 24, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants