Testing
Testing
Section titled “Testing”vcpkg-harbor uses pytest for testing.
Running Tests
Section titled “Running Tests”# Run all tests./scripts/test.sh
# Run specific filepytest tests/test_health.py -v
# Run specific testpytest tests/test_cache.py::test_upload_and_download_package -v
# Run with coveragepytest tests/ --cov=vcpkg_harbor --cov-report=htmlTest Structure
Section titled “Test Structure”tests/├── __init__.py├── conftest.py # Shared fixtures├── test_config.py # Configuration tests├── test_health.py # Health endpoint tests├── test_cache.py # Cache API tests└── test_storage/ # Storage backend tests ├── test_filesystem.py └── test_minio.pyFixtures
Section titled “Fixtures”Application Fixture
Section titled “Application Fixture”@pytest.fixturedef app(settings: Settings): """Create test FastAPI application.""" return create_app(settings)
@pytest.fixturedef client(app) -> TestClient: """Create test client.""" return TestClient(app)Settings Fixture
Section titled “Settings Fixture”@pytest.fixturedef settings() -> Settings: """Create test settings with filesystem backend.""" return Settings( storage={"type": "filesystem", "path": "/tmp/test"}, logging={"level": "DEBUG", "file": None}, )Writing Tests
Section titled “Writing Tests”Testing Endpoints
Section titled “Testing Endpoints”def test_health_endpoint(client: TestClient): response = client.get("/health") assert response.status_code == 200 data = response.json() assert "status" in dataTesting Storage Backends
Section titled “Testing Storage Backends”@pytest.mark.asyncioasync def test_filesystem_put_get(): backend = FilesystemBackend(path="/tmp/test") await backend.initialize()
# Upload data = async_iter([b"test data"]) info = await backend.put("pkg", "1.0", "sha", data) assert info.size > 0
# Download chunks = [] async for chunk in backend.get("pkg", "1.0", "sha"): chunks.append(chunk) assert b"".join(chunks) == b"test data"Integration Tests
Section titled “Integration Tests”For testing with real services (MinIO), use Docker:
@pytest.fixture(scope="session")def minio_container(): """Start MinIO container for integration tests.""" # Uses testcontainers or docker-composeCI Testing
Section titled “CI Testing”GitHub Actions runs tests on every PR:
- name: Run tests env: VCPKG_STORAGE_TYPE: filesystem run: pytest tests/ -v --cov=vcpkg_harborCoverage
Section titled “Coverage”View coverage report:
# Generate HTML reportpytest tests/ --cov=vcpkg_harbor --cov-report=html
# Open reportopen htmlcov/index.htmlCoverage is uploaded to Codecov on CI.