Testing Containerlab#
Containerlab's test program largely consists of:
- Go-based unit tests
- RobotFramework-based integration tests
Integration Tests#
The integration tests are written in RobotFramework and are located in the tests
directory. The tests are run using the rf-run
command that wraps robot
command. The tests are run in a Docker container, so you don't need to install RobotFramework on your local machine.
Local execution#
To execute the integration tests locally you have to install the python environment with the required dependencies. If you're using pyenv
you can use the following commands:
-
Create a venv and activate it
-
Install the dependencies
Usually you would run the tests using the locally built containerlab binary that contains the unreleased changes. The typical workflow then starts with building the containerlab binary:
The newly built binary is located in the bin
directory. In order to let the test runner script know where to find the binary, you have to set the CLAB_BIN
environment variable before calling the rf-run
script:
Note
The test runner script requires you to specify the runtime as its first argument. The runtime can be either docker
or podman
. Containerlab primarily uses Docker as the default runtime, hence the number of tests written for docker outnumber the podman tests.
Selecting the test suite#
Containerlab's integration tests are grouped by a topic, and each topic is mapped to a directory under the tests
directory and RobotFramework allows for a flexible selection of tests/test suites to run. For example, to run all the smoke test cases, you can use the following command:
since 01-smoke
is a directory containing all the smoke test suites.
Consequently, in order to run a specific test suite you just need to provide a path to it. E.g. running the 01-basic-flow.robot
test suite from the 01-smoke
directory:
Note
Selecting a specific test case in a test suite is not supported, since test suites are written in a way that test cases depend on previous ones.
Inspecting the test results#
RobotFramework generates a detailed report in HTML and XML formats that can be found in the tests/out
directory. The exact paths to the reports are printed to the console after the test run.