Skip to content
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

Include a materialized copy of built-in templates #2146

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

pietern
Copy link
Contributor

@pietern pietern commented Jan 14, 2025

Changes

Include a materialized copy of built-in templates as reference output.

This updates the output comparison logic to work against an output directory.

@pietern pietern temporarily deployed to test-trigger-is January 14, 2025 19:25 — with GitHub Actions Inactive
@pietern
Copy link
Contributor Author

pietern commented Jan 14, 2025

@denik I tried using testutil.ReplaceOutput instead of using the replacement context directly. This takes care of a UUID in the output. But it also replaces numbers with <NUMID> which is not valid JSON.

@denik
Copy link
Contributor

denik commented Jan 15, 2025

@denik I tried using testutil.ReplaceOutput instead of using the replacement context directly. This takes care of a UUID in the output. But it also replaces numbers with which is not valid JSON.

We could easily fix that with by using "<NUMID>" instead.

@denik
Copy link
Contributor

denik commented Jan 15, 2025

I think it would be useful (could be a follow up) to also run "bundle validate" and "bundle deploy" and other commands on these, so bundle/init is not a great name, because it's not just init. bundle/templates ?

pietern added a commit that referenced this pull request Jan 15, 2025
## Changes

Replacement was split between the type `ReplacementContext` and the
`ReplaceOutput` function. The latter also ran a couple of regular
expressions. This change consolidates them such that it is up to the
caller to compose the set of replacements to use.

This change is required to accommodate UUID replacement in #2146.
@pietern pietern temporarily deployed to test-trigger-is January 15, 2025 11:20 — with GitHub Actions Inactive
@pietern pietern temporarily deployed to test-trigger-is January 15, 2025 12:20 — with GitHub Actions Inactive
@pietern pietern temporarily deployed to test-trigger-is January 15, 2025 12:25 — with GitHub Actions Inactive
@pietern pietern force-pushed the acceptance-init-with-output branch from 3884a71 to f45b156 Compare January 16, 2025 15:45
@pietern pietern temporarily deployed to test-trigger-is January 16, 2025 15:45 — with GitHub Actions Inactive
@pietern
Copy link
Contributor Author

pietern commented Jan 16, 2025

#2166 makes sure that initialized templates are formatted per ruff.

@pietern pietern marked this pull request as ready for review January 16, 2025 15:46
@pietern pietern changed the title Include the materialized template as reference output Include a materialized copy of built-in templates Jan 16, 2025
@pietern pietern requested a review from denik January 16, 2025 15:49
t.Logf("Overwriting: %s", pathExpected)
testutil.WriteFile(t, pathExpected, valueNew)
} else {
t.Logf("Removing: %s", pathExpected)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this? It's helpful to update golden test files when files are deleted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-removal functionality is quite helpful actually. I'd prefer that we keep it.

We can do so by changing readIfExists to return (contents string, exists bool) to distinguish between empty and missing.

t.Errorf("Unexpected output: %s", f)
if strings.HasPrefix(name, "out") {
t.Errorf("Unexpected output: %s", relPath)
if strings.HasPrefix(relPath, "out") {
// We have a new file starting with "out"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe unrelated to this PR: This comment string seems inaccurate. Not sure what this refers to.

continue
}
t.Errorf("Unexpected output: %s", f)
if strings.HasPrefix(name, "out") {
t.Errorf("Unexpected output: %s", relPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the output file/directory is unexpected why are we doing assertions on it? Why have two places in the code where we figure out the expected paths and assert on their content?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants