-
-
Notifications
You must be signed in to change notification settings - Fork 1
feat(cli): implement test subcommand for autopkgtests #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Tests: smoke | ||
| Depends: @ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/bin/sh | ||
| set -e | ||
|
|
||
| debmagic --version | ||
| debmagic test --help |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| # Running package tests | ||
|
|
||
| Quick reference for running a package's declared Debian autopkgtest tests with `debmagic test`. | ||
|
|
||
| ## TL;DR | ||
|
|
||
| - Entry point: `debmagic test` — runs tests from `debian/tests/control` against the `.debs` of a prior `debmagic build` | ||
| - Requires a completed build in the same build root (or pass `--changes` to point at exported artifacts) | ||
|
|
||
| ```shell | ||
| cd your-package | ||
| debmagic build binary --driver docker | ||
| debmagic test --driver docker | ||
| ``` | ||
|
|
||
| ## What it does | ||
|
|
||
| `debmagic test` installs the binary packages from a prior build and runs the package's declared autopkgtest tests (`debian/tests/control`) | ||
| inside a **fresh, separate** driver-managed environment. | ||
| The test environment is never the build environment — even when `--persistent` reuses a container across runs, | ||
| the test tree is reset and the `.debs` are reinstalled each time. | ||
|
|
||
| The driver *is* the testbed: `autopkgtest` runs with the `null` backend inside the container (or on the host for the bare driver). No `autopkgtest-virt-*` backends are used. | ||
|
|
||
| ## Available options | ||
|
|
||
| | Option | Description | | ||
| |---|---| | ||
| | `--driver <...>` | Test environment driver (defaults to the driver recorded in the prior build's `build.json`) | | ||
| | `--persistent` | Retain the test environment after the run for reattach/debug | | ||
| | `--strict` | Treat skipped tests and "no tests declared" as failures (exit code 2) | | ||
| | `--changes <path>` | Path to a `.changes` file whose directory supplies the built `.debs` (for pipeline use) | | ||
| | `--distro <name>` | Override the target distro for the test environment (defaults to the prior build's distro from `build.json`, not the changelog) | | ||
| | `--proposed` | Enable the `<release>-proposed` pocket in the test environment | | ||
| | `--apt-mirror <url>` | Mirror URL (same as [`debmagic build`](build.md)) | | ||
| | `--source-dir <dir>` | Directory containing the `debian/` package directory | | ||
| | `--allow-host-test` | Allow the bare driver, which runs autopkgtest as root on the host | | ||
|
|
||
| [`debmagic shell`](#inspecting-a-failed-test-run) — attach an interactive shell to a test environment | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how do we select build/test environment? |
||
|
|
||
| Driver-specific flags (`--driver-docker-base-image`, `--driver-lxd-*`) mirror `debmagic build`. | ||
|
|
||
| ## Picking a driver | ||
|
|
||
| Use the same drivers as for builds. Pass `--driver` explicitly (or rely on the driver recorded in the prior build's `build.json`): | ||
|
|
||
| | Driver | Isolation | | ||
| |---|---| | ||
| | `lxd` / `incus` | Full container isolation | | ||
| | `docker` | Full container isolation | | ||
| | `bare` | None — tests run as root on the host; requires `--allow-host-test` | | ||
|
|
||
| ## Exit codes | ||
|
|
||
| | Code | Meaning | | ||
| |---|---| | ||
| | `0` | All tests passed, or skips/no-tests were allowed | | ||
| | `1` | Test failure, testbed error, or other autopkgtest error | | ||
| | `2` | Strict-only failure: skipped tests or no tests declared under `--strict` | | ||
|
|
||
| autopkgtest skips tests whose `Restrictions:` the `null` backend cannot satisfy (e.g. `isolation-container`, `isolation-machine`). Skips are reported loudly; use `--strict` to escalate them to exit code 2. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can pass capabilities to the null driver which it then pretends to have. and we are in a container (or even lxd vm), so we can give those caps to the null driver. |
||
|
|
||
| If no `debian/tests/control` exists (or it declares no tests), the run exits 0 with a notice — or exit 2 under `--strict`. | ||
|
|
||
| ## Inspecting a failed test run | ||
|
|
||
| On failure with a TTY, `debmagic test` offers an interactive shell inside the test environment (destroyed on shell exit unless `--persistent` was used). With a persistent test environment: | ||
|
|
||
| ```shell | ||
| # if you're in the package still | ||
| debmagic shell | ||
| # from the outside: | ||
| debmagic shell --source-dir /path/to/parent/of/debian/dir | ||
| ``` | ||
|
|
||
| Test output and logs are exported to a `test/` subdirectory of the build root; the path is printed at the end of the run. | ||
|
|
||
| ## Prior build required | ||
|
|
||
| By default `debmagic test` resolves the prior build from the build root (same layout as `debmagic shell`). If no build artifacts are found: | ||
| run `debmagic build` first | ||
|
|
||
| Use `--changes` to supply a `.changes` file from an exported output directory instead. | ||
|
|
||
| ## Bare driver | ||
|
|
||
| The bare driver runs autopkgtest as root directly on the host. | ||
| This violates the no-leak principle for normal use — pass `--allow-host-test` to opt in explicitly. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.debs is not right, just leave it out and say need prior build