Repository navigation
Enhancement | CLI tests for project init/create with golden files - #388
Merged
Merged
Conversation
- tests/test_modules/test_project_cli.py: `project init` (clone, git init, project.yaml; a second run updates the template and keeps project.yaml) and `project create` on a snapshot of the real template, with project.yaml filled as CI does. Golden files hold the list of created files and the rendered ones verbatim; copied files must match the template. Every created .tf/.tfvars parses, every layer passes validate-layout (backend layers stop and point to --skip-validation, by design), and with tofu installed `tofu fmt -check` passes. - Regression test for #321: the first `tofu init --skip-validation` of a new backend layer reaches tofu with its backend config. - project create exited 0 without project.yaml and on an already created project; it now exits 1. - The template source of the render functions was a default argument frozen at import time; it is resolved at call time now, like the destination. - tests/project_template/: snapshot of le-tf-infra-aws-template@e369df9, snapshot.py to refresh it, UPDATE_GOLDEN=1 to regenerate the golden files. Closes #321 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 38 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Coverage Report for CI Build 46002380050Coverage increased (+2.4%) to 84.827%Details
Uncovered Changes
Coverage Regressions20 previously-covered lines in 1 file lost coverage.
Coverage Stats
💛 - Coveralls |
binbashdevops
approved these changes
Nov 27, 2026
Contributor
Author
|
@claude review |
This was referenced Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
project(tests/test_modules/test_project_cli.py, 9 new), on a snapshot of the real project template:project init: clones the template, runsgit init, dropsproject.yaml. A second run updates the template (checkout master+pull) and keeps the user'sproject.yaml.project create, withproject.yamlfilled the way the ref-arch integration test does:tests/project_template/golden/): the list of the 56 files it creates (symlinks included) and the 8 it renders from templates, verbatim. Every copied file must be identical to the template..tf/.tfvarsparses as HCL.validate-layout. Thebase-tf-backendlayers fail on purpose and point to--skip-validation, since their backend block stays commented out until their first apply.tofuinstalled,tofu fmt -check -recursivepasses on the result (skipped where tofu isn't installed, e.g. theunit_testsjob).project createbeforeinit, and a secondproject create: exit 1, and nothing changes.tofu init --skip-validationof a new backend layer reaches tofu with its-backend-config. It passes onmaster, so Malformed config.tf file when first creating backend layer #321 is already fixed.leverage/modules/project.py:project createexited 0 withoutproject.yamland on an already created project. It now exits 1, asvalidate-layoutdoes since Fix | tf: init --layers backend key per layer, validate-layout exit code + error path tests #385.source=TEMPLATE_DIR), frozen at import time. It is resolved at call time now, asdestinationalready was, so they always use the module's current template directory.tests/project_template/: snapshot ofle-tf-infra-aws-template@e369df9(template/andle-resources/, verbatim).snapshot.pyrefreshes it, andUPDATE_GOLDEN=1 poetry run pytest tests/test_modules/test_project_cli.pyregenerates the golden files; review that diff, it is whatproject creategenerates.Why?
H7 in #346,
projectpart:CliRunnertests forproject init/create, always assertingexit_code, plus golden files of theproject createoutput. It waited for #334, merged now.Checked that the golden files catch output changes: rendering with
trim_blocksor putting the regional layers in another directory fails them.Not covered
tofu validateon the created project: it needs providers and modules downloaded, so it doesn't fit the unit tests. It could be a bats test in the integration job, in a follow-up.Checks
tofu fmt -checktest included, tofu installed locally)References
projectpart)build.envshows the template still rendersTERRAFORM_IMAGE_TAG=and noTF_BINARY; once fixed there, refresh the snapshot and golden files🤖 Generated with Claude Code