Repository navigation
Testing your rock
Every rock is tested in two complementary ways:
-
Your tests: Spread tests, written by the user, run with
rockcraft test. They only run if aspread.yamlexists next to yourrockcraft.yaml. - Generic checks: a fixed set of checks that run on every rock, with nothing for you to write.
If spread.yaml exists in the rock's directory, the CI runs rockcraft test as part of the build stage. If the file does not exist, this step is skipped (the generic checks still run).
rockcraft.yaml
spread.yaml # Spread project: backend, systems, how to load the rock
spread/
└── general/
└── test/
└── task.yaml # One test
The example below uses the craft backend, loads the rock into Docker and cleans up afterwards. Replace my-rock-name with your rock's name.
project: my-rock-name
backends:
craft:
type: craft
systems:
- ubuntu-24.04:
#- ubuntu-22.04:
suites:
spread/general/:
summary: General integration tests
prepare: |
sudo snap install docker
# For 'rockcraft.skopeo'
sudo snap install --classic rockcraft
# Wait for docker daemon to come online
sudo apt install --yes retry
retry --times=10 --delay 2 -- docker run hello-world
sudo apt remove --yes retry
# Load the rock into docker
sudo rockcraft.skopeo --insecure-policy copy "oci-archive:$CRAFT_ARTIFACT" docker-daemon:my-rock-name:latest
restore: |
docker image rm --force my-rock-name:latest
exclude:
- .git
kill-timeout: 1h$CRAFT_ARTIFACT is provided by Rockcraft and points to the packed rock.
Each test is specified as a directory under the suite containing a task.yaml. The execute block is a Bash script; the test fails if it exits with a non-zero status.
summary: test the 'my-rock-name' project
execute: |
# Replace with commands that exercise your rock, for example:
docker run --rm my-rock-name:latest exec -- ls /Add more directories (for example spread/general/another-test/task.yaml) to add more tests to the suite. See the spread documentation and the rockcraft test reference for the full syntax.
You need Rockcraft and LXD. Run:
sudo snap install rockcraft --classic
sudo snap install lxdThen, from the directory containing spread.yaml, run:
rockcraft testTo run every test in a repository that hosts several rocks use:
for dir in $(find . -name spread.yaml -exec dirname {} \;); do
(cd "$dir" && rockcraft test)
doneSpread leaves state behind, which the template's .gitignore already ignores: .craft-spread*/ and .spread-reuse*. Remove them if you want a clean start.
After all rocks are built, the Test stage runs these checks against every resulting image, whether or not you wrote tests:
| Check | What it does | Fails the pipeline |
|---|---|---|
| OCI compliance | Unpacks the image with umoci and validates its layout. |
Yes |
| Black box | Starts the image and checks that pebble runs. |
Yes |
| Efficiency | Analyses the image with Dive. | No (informational) |
| Vulnerabilities | Scans for vulnerabilities with Trivy. | Yes |
| Malware | Scans the image filesystem. | Yes |
The upload stage only starts after the Test stage succeeds.
Note
The Test stage reports its results per rock in the GitHub Actions run. If the vulnerability check fails, see Troubleshooting.