melange includes a first-classDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/chainguard-dev/melange/llms.txt
Use this file to discover all available pages before exploring further.
test command that lets you validate the packages you build using the same pipeline DSL you already know from melange build. Tests run in isolated guest environments, can use test fixture files, and integrate naturally with both local development and CI workflows.
The test: block
Add a test: key at the top level of your melange YAML to define tests for the main package, or nest it inside a subpackages: entry to test a specific subpackage. A test: block follows exactly the same structure as the pipeline: section — it has an environment: for specifying required packages and a pipeline: of runs: and uses: steps.
Here is the full gnu-hello example from the melange README extended with a test block:
Unlike the build guest, each test runs in a fresh container built by apko that contains only the Package Under Test (PUT) plus whatever you list in
test.environment.contents.packages. The main test: block automatically includes the main package; a subpackage test: block automatically includes that subpackage.Test environment details
Workspace
Just like a build, all test pipeline steps share a single workspace directory that is mounted as the current working directory. You can place test fixture files (scripts, data files, config snippets) into a directory on your host and pass it via--source-dir. melange copies those files into the workspace before the tests run.
For example, to test a Python data-processing package, create a fixture file:
--source-dir so the file lands in the workspace as ./pandas-test.py:
Guest container
The test guest is built fresh for each test context using apko. The package under test is always included automatically; additional packages come fromtest.environment.contents.packages. For example, a main-package test:
py3-pandas, busybox, python-3, and their transitive dependencies.
A subpackage test works the same way, with the subpackage as the automatic PUT:
php-8.2-msgpack-dev, busybox, wolfi-base, and their transitive dependencies.
Writing a standalone test file
Tests can be embedded in the same YAML as the build, or placed in a separate file. A standalone test file requires a minimal set of placeholder fields to satisfy the parser:Using predefined pipelines in tests
Test pipelines supportuses: steps just like build pipelines. Point --pipeline-dirs at a directory containing custom pipeline YAML files:
Running tests
Basic invocation
package.name in the YAML file.
Targeting a specific package
Pass a second positional argument to test a different package with the same test file. This is useful for sharing a single test file across versioned packages (e.g.,php-8.1, php-8.2, php-8.3):
Key flags
| Flag | Description |
|---|---|
--arch | Architecture to test for (e.g., aarch64, x86_64). Default: host arch. |
--runner | Runner to use: bubblewrap, docker, or qemu. |
--source-dir | Directory containing test fixture files to copy into the workspace. |
--pipeline-dirs | Directory (or directories) with custom pipeline definitions. |
--keyring-append | Path or URL to additional signing keys for the APK resolver. |
--repository-append | Path or URL to additional APK repositories. |
--test-package-append | Extra packages added to every test environment. |
