Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/distro_image_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jobs:
- name: Run fboss-image build
run: ./fboss-image/distro_cli/fboss-image build fboss-image/from_source.json

- name: Run distro_cli tests
run: |
docker exec ${USER}-fboss-image-builder ctest -R distro_cli -V

- name: Cleanup
if: always()
run: |
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1154,3 +1154,6 @@ if (GITHUB_ACTIONS_BUILD)
fsdb_all_services
)
endif()

# FBOSS Image Builder distro_cli tests
include(cmake/FbossImageDistroCliTests.cmake)
36 changes: 36 additions & 0 deletions cmake/FbossImageDistroCliTests.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# CMake to build and test fboss-image/distro_cli

# In general, libraries and binaries in fboss/foo/bar are built by
# cmake/FooBar.cmake

include(FBPythonBinary)

file(GLOB DISTRO_CLI_TEST_SOURCES
"fboss-image/distro_cli/tests/*_test.py"
)

file(GLOB DISTRO_CLI_TEST_HELPERS
"fboss-image/distro_cli/tests/test_helpers.py"
)

file(GLOB_RECURSE DISTRO_CLI_LIB_SOURCES
"fboss-image/distro_cli/builder/*.py"
"fboss-image/distro_cli/cmds/*.py"
"fboss-image/distro_cli/lib/*.py"
"fboss-image/distro_cli/tools/*.py"
)

file(COPY "fboss-image/distro_cli/tests/data" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/fboss-image/distro_cli/tests")

add_fb_python_unittest(
distro_cli_tests
BASE_DIR "fboss-image"
SOURCES
${DISTRO_CLI_TEST_SOURCES}
${DISTRO_CLI_TEST_HELPERS}
${DISTRO_CLI_LIB_SOURCES}
ENV
"PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}/fboss-image/distro_cli"
)

install_fb_python_executable(distro_cli_tests)
68 changes: 64 additions & 4 deletions fboss-image/distro_cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,56 @@ Components are built in the following order:

### Running Tests

#### With Bazel (Recommended)

```bash
# Run all tests
cd fboss-image/distro_cli
python3 -m unittest discover -s tests -p '*_test.py'
bazel test //fboss/fboss-image/distro_cli:all

# Run specific test
python3 -m unittest tests.cli_test
bazel test //fboss/fboss-image/distro_cli:cli_test

# Run with detailed output
bazel test //fboss/fboss-image/distro_cli:all --test_output=all
```

#### With pytest

```bash
# Run all tests (from fboss-image directory)
cd fboss-image
PYTHONPATH=. python3 -m pytest distro_cli/tests/ -v

# Run specific test file
PYTHONPATH=. python3 -m pytest distro_cli/tests/cli_test.py -v

# Run specific test class or method
PYTHONPATH=. python3 -m pytest distro_cli/tests/cli_test.py::CLITest::test_cli_creation -v
```

#### With unittest

```bash
# Run all tests (from fboss-image directory)
cd fboss-image
PYTHONPATH=. python3 -m unittest discover -s distro_cli/tests -p '*_test.py'

# Run specific test module
PYTHONPATH=. python3 -m unittest distro_cli.tests.cli_test

# Run specific test class
PYTHONPATH=. python3 -m unittest distro_cli.tests.cli_test.CLITest
```

### Linting

```bash
# With ruff (from distro_cli directory)
cd fboss-image/distro_cli
python3 -m ruff check .

# With bazel (from repository root)
bazel test //private-fboss/fboss-image/distro_cli:lint_check
```

### Project Structure
Expand Down Expand Up @@ -152,7 +188,7 @@ fboss-image/distro_cli/
The CLI uses a custom OOP wrapper around argparse (stdlib only, no external dependencies):

```python
from lib.cli import CLI
from distro_cli.lib.cli import CLI

# Create CLI
cli = CLI(description='My CLI')
Expand All @@ -171,3 +207,27 @@ device.add_command('ssh', ssh_func, help_text='SSH to device')
# Run
cli.run(setup_logging_func=setup_logging)
```

## Running Tests

### Quick Tests (Default)
Run all fast unit tests (excludes long-running E2E tests):
```bash
python3 -m pytest distro_cli/tests/ -v
# or explicitly exclude e2e tests:
python3 -m pytest distro_cli/tests/ -m "not e2e" -v
```

### E2E Tests Only
Run only the end-to-end tests (kernel build, SAI build):
```bash
python3 -m pytest distro_cli/tests/ -m e2e -v -s
```

### All Tests (Including E2E)
Run everything:
```bash
python3 -m pytest distro_cli/tests/ -v -s
```

**Note:** E2E tests can take 10-60 minutes and require actual source files (kernel sources, SAI SDK, etc.).
Loading