- Added comprehensive test suite for Buildah module functionality. - Included tests for Builder pattern, image operations, and container operations. - Added documentation describing test structure, execution, and details.
4.1 KiB
Buildah Module Tests
This document describes the test scripts for the Buildah module in the SAL library. These tests verify the functionality of the Buildah module's container and image operations.
Test Structure
The tests are organized into three main scripts:
- Builder Pattern (
01_builder_pattern.rhai
): Tests for the Builder pattern, including creating containers, running commands, and working with container content. - Image Operations (
02_image_operations.rhai
): Tests for image-related operations like pulling, tagging, listing, and removing images. - Container Operations (
03_container_operations.rhai
): Tests for container-related operations like configuration, isolation, and content management.
Additionally, there's a runner script (run_all_tests.rhai
) that executes all tests and reports results. The runner script contains simplified versions of the individual tests to avoid dependency issues.
Running the Tests
To run all tests, execute the following command from the project root:
herodo --path src/rhai_tests/buildah/run_all_tests.rhai
To run individual test scripts:
herodo --path src/rhai_tests/buildah/01_builder_pattern.rhai
Test Details
Builder Pattern Test
The Builder Pattern test (01_builder_pattern.rhai
) verifies the following functions:
bah_new
: Creating a new Builder with a container from a specified image- Builder properties:
container_id
,name
,image
,debug_mode
run
: Running commands in the containerwrite_content
: Writing content to files in the containerread_content
: Reading content from files in the containerset_entrypoint
: Setting the container's entrypointset_cmd
: Setting the container's commandadd
: Adding files to the containercopy
: Copying files to the containercommit
: Committing the container to an imageremove
: Removing the containerimages
: Listing imagesimage_remove
: Removing images
Image Operations Test
The Image Operations test (02_image_operations.rhai
) verifies the following functions:
image_pull
: Pulling images from registriesimage_tag
: Tagging imagesimages
: Listing imagesbuild
: Building images from Dockerfilesimage_remove
: Removing images
The test creates a temporary directory with a Dockerfile for testing the build functionality.
Container Operations Test
The Container Operations test (03_container_operations.rhai
) verifies the following functions:
reset
: Resetting a Builder by removing its containerconfig
: Configuring container propertiesrun_with_isolation
: Running commands with isolation- Content operations: Creating and executing scripts in the container
commit
with options: Committing a container with additional configuration
Test Runner
The test runner script (run_all_tests.rhai
) provides a framework for executing all tests and reporting results. It:
- Checks if Buildah is available before running tests
- Skips tests if Buildah is not available
- Contains simplified versions of each test
- Runs each test in a try/catch block to handle errors
- Catches and reports any errors
- Provides a summary of passed, failed, and skipped tests
Buildah Requirements
These tests require the Buildah tool to be installed and available in the system's PATH. The tests will check for Buildah's availability and skip the tests if it's not found, rather than failing.
Adding New Tests
To add a new test:
- Create a new Rhai script in the
src/rhai_tests/buildah
directory - Add a new test section to the
run_all_tests.rhai
script - Update this documentation to include information about the new test
Best Practices for Writing Tests
When writing tests for the Buildah module:
- Always check if Buildah is available before running tests
- Use unique names for containers and images to avoid conflicts
- Clean up any containers, images, or files created during testing
- Use assertions to verify expected behavior
- Print clear messages about what's being tested
- Handle errors gracefully
- Make tests independent of each other
- Keep tests focused on specific functionality