- Implement complete test suite with 63 examples (49 unit + 14 integration tests) - Add RSpec, FactoryBot, WebMock, and SimpleCov testing dependencies - Create mocked integration tests eliminating need for real Docker containers - Fix SQLite method signature to accept login/password parameters - Enhance container discovery to handle nil labels gracefully - Add test coverage reporting and JUnit XML output for CI - Update GitHub Actions workflow to run tests before Docker builds - Add Ruby 3.3 setup with gem caching for faster CI execution - Create CI test script and comprehensive testing documentation - Ensure Docker builds only proceed when all tests pass 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1.7 KiB
1.7 KiB
Testing Guide
This document describes how to run tests for the Baktainer project.
Quick Start
# Run all tests
bundle exec rspec
# Run only unit tests
bundle exec rspec spec/unit/
# Run only integration tests
bundle exec rspec spec/integration/
# Run with coverage
COVERAGE=true bundle exec rspec
CI Testing
For continuous integration, use the provided CI test script:
./bin/ci-test
This script:
- Runs all tests (unit and integration)
- Generates JUnit XML output for CI reporting
- Creates test results in
tmp/rspec_results.xml
Test Structure
- Unit Tests (
spec/unit/
): Test individual classes and methods in isolation with mocked dependencies - Integration Tests (
spec/integration/
): Test complete workflows using mocked Docker API calls - Fixtures (
spec/fixtures/
): Test data and factory definitions
Key Features
- No Docker Required: All tests use mocked Docker API calls
- Fast Execution: Tests complete in ~2 seconds
- Comprehensive Coverage: 63 examples testing all major functionality
- CI Ready: Automatic test running in GitHub Actions
GitHub Actions
The CI pipeline automatically:
- Runs all tests on every push and pull request
- Prevents Docker image builds if tests fail
- Uploads test results as artifacts
- Uses Ruby 3.3 with proper gem caching
Local Development
Install dependencies:
bundle install
Run tests with coverage:
COVERAGE=true bundle exec rspec
open coverage/index.html # View coverage report
Test Dependencies
- RSpec 3.12+ for testing framework
- FactoryBot for test data generation
- WebMock for HTTP request mocking
- SimpleCov for coverage reporting
- RSpec JUnit Formatter for CI reporting