This directory contains unit tests for the ngfw_pkgtools project.
# Run all tests with coverage (excludes remote tests)
make test
# Format code before testing
make format
# Run linter
make lintRemote tests verify that repositories in repositories.yaml actually exist and are accessible. These tests require:
- Network access
- SSH credentials configured
- SSH agent running
# Run only remote tests
docker-compose -f docker-compose.dev.yml exec ngfw-pkgtools-dev pytest -v -m remote
# Run all tests including remote tests
docker-compose -f docker-compose.dev.yml exec ngfw-pkgtools-dev pytest -v --run-remote
# Run all tests except remote tests (default)
docker-compose -f docker-compose.dev.yml exec ngfw-pkgtools-dev pytest -v -m "not remote"# Run tests
docker-compose -f docker-compose.dev.yml exec ngfw-pkgtools-dev pytest -v
# Run tests with coverage
docker-compose -f docker-compose.dev.yml exec ngfw-pkgtools-dev pytest -v --cov=lib --cov-report=term-missing
# Run specific test file
docker-compose -f docker-compose.dev.yml exec ngfw-pkgtools-dev pytest tests/test_repoinfo.py -v
# Run specific test
docker-compose -f docker-compose.dev.yml exec ngfw-pkgtools-dev pytest tests/test_repoinfo.py::TestRepositoryInfo::test_repository_info_git_url_construction -v# Install dependencies
pip3 install pytest pytest-cov PyYAML GitPython requests
# Run tests from project root
pytest -v --cov=lib --cov-report=term-missingTests for the lib.repoinfo module, which handles repository configuration loading.
Test Classes:
-
TestRepositoryInfo - Tests the RepositoryInfo dataclass
- Git URL construction
- Default values
-
TestListRepositories - Tests repository listing with mock data
- Product-specific git_base_url overrides
- Default git_base_url fallback
- Repository-level git_base_url
- Product-specific attributes (default_branch, etc.)
- Obsolete repository filtering
- Product filtering
- Private attribute handling
-
TestActualRepositoriesYaml - Integration tests with actual repositories.yaml
- Velo repositories use Gerrit (https://code.arista.io/efw)
- MFW repositories use GitHub
- EFW repositories use GitHub
- Git URL validation
Current coverage: 88% for lib/repoinfo.py
The tests cover:
- ✅ Product-specific git URL configuration
- ✅ Multi-level git_base_url resolution (product → repository → default)
- ✅ Repository filtering by product
- ✅ Obsolete repository handling
- ✅ Product-specific attributes
- ✅ Git URL construction
- ✅ Gerrit repository name mapping
- ✅ Remote repository existence (optional, requires network)
When adding new functionality to the codebase:
- Create test methods in the appropriate test class
- Use descriptive test names:
test_<what_is_being_tested> - Add docstrings explaining what the test validates
- Use fixtures for reusable test data
- Run tests to ensure they pass:
make test
def test_new_feature(self, sample_yaml_file):
"""Test that new feature works correctly"""
# Arrange
repos = repoinfo.list_repositories('product', yaml_file=sample_yaml_file)
# Act
result = some_function(repos)
# Assert
assert result == expected_valueThese tests should be run:
- Before committing code
- In CI/CD pipelines
- Before merging pull requests
Make sure you're running tests from the project root directory.
Ensure the conftest.py file is present and properly configured.
Start the container with make up before running tests.