6. Prove it in the testlab
Declare a test block and let the three-run protocol prove convergence in a disposable instance.
After this lesson you can
- Declare a test block with an image and static steps - Run the three-run protocol in a docker instance - Debug a failing test with --keep
Before you start: Write your own package
A test block in package.wcl names an image and one or more static steps (no variable references). config-weave test boots a disposable instance — a docker container by default, a vmlab VM when the test needs a real machine — copies the binary and a synthesized playbook in, and runs the three-run protocol: check (must report not configured), apply (must converge), apply again in a fresh process (must change nothing).
Run 2 catches resources that don't converge; run 3 catches the subtler bug — state that only looks converged to the process that created it. Filter with pkg or pkg:test, and keep a failing instance alive with --keep to shell in and inspect.
§ 1Exercise: Test your package end-to-end
Add a test for your dir_present resource and run it in a docker instance.
// in pkgs/mypkg/package.wcl
test "dir_present_converges" {
description = "dir_present creates the directory and is idempotent"
image = "debian:12"
step "make-dir" {
description = "Create a work directory"
resource = "dir_present"
properties { path = "/var/tmp/weave-test" }
}
}
Expected result
config-weave test ./my-playbook mypkg (docker running, static linux binary via --binary if your dev build is dynamic) reports the test passed and exits 0.
Hint
Unqualified resource refs in a test resolve to the declaring package — dir_present, not mypkg.dir_present.
§ 2Exercise: Watch the protocol catch a bug
Make apply() create the state somewhere check() doesn't look (e.g. append a suffix to the path), re-run the test, and read which run fails.
Expected result
The test fails on run 2's re-check (or run 3) with the step still not configured; --keep leaves the container up so you can inspect what apply actually wrote. Revert the sabotage and the test passes again.