Support injecting dev variables in tests#181
Merged
alex-hunt-materialize merged 4 commits intomainfrom Apr 7, 2026
Merged
Conversation
bobbyiliev
previously approved these changes
Apr 7, 2026
Collaborator
bobbyiliev
left a comment
There was a problem hiding this comment.
Looks good! Just one minor nit/question.
test/src/commands/init.rs
Outdated
Comment on lines
+331
to
+357
| fn inject_into_module(content: &str, module_name: &str, vars: &[&str]) -> String { | ||
| let target = format!("module \"{module_name}\""); | ||
| let mut lines: Vec<&str> = content.lines().collect(); | ||
| let mut in_module = false; | ||
| let mut insert_after = None; | ||
|
|
||
| for (i, line) in lines.iter().enumerate() { | ||
| if line.contains(&target) { | ||
| in_module = true; | ||
| } | ||
| if in_module && line.trim_start().starts_with("source") { | ||
| insert_after = Some(i); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if let Some(idx) = insert_after { | ||
| let mut offset = 1; | ||
| lines.insert(idx + offset, ""); | ||
| offset += 1; | ||
| for var in vars { | ||
| let line = format!(" {var}"); | ||
| // Leak is fine here – this runs once during init. | ||
| lines.insert(idx + offset, Box::leak(line.into_boxed_str())); | ||
| offset += 1; | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
Nit: I think that if insert_after is None (eg. module block not found in main.tf), this silently returns the content unchanged. Might be worth logging a warning or returning an Err so a missing/renamed module doesn't go unnoticed?
bobbyiliev
approved these changes
Apr 7, 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.
Support injecting dev variables in tests.
This makes it much easier to test development versions of the helm chart, orchestratord, and environmentd.