-
Notifications
You must be signed in to change notification settings - Fork 631
Allow indented YAML in tests #4272
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
Open
Open
+382
−155
Conversation
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
cbandy
cbandy
commented
Sep 7, 2025
Comment on lines
-25
to
+26
assert.DeepEqual(t, string(b), strings.TrimSpace(`
items:
- key: two
path: three
name: one
`)+"\n")
assert.Assert(t, MarshalsTo(out, `
items:
- key: two
path: three
name: one
`))
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.
📝 Here's a diff between left-justified spaces and tabs indented relevant to nearby Go code.
@cbandy
cbandy
force-pushed
the
indent-yaml
branch
from
September 7, 2025 06:16
5c54b9e
to
ecf9fae
Compare
This allows Go tests to indent multi-line YAML literals to match the surrounding code/tests. Go code is indented with tabs, so tabs are converted to match the encoder's two-space indentation.
@cbandy
cbandy
force-pushed
the
indent-yaml
branch
from
September 8, 2025 20:11
ecf9fae
to
54c8b7d
Compare
@cbandy
cbandy
force-pushed
the
indent-yaml
branch
from
September 8, 2025 22:32
c7baa8b
to
5080935
Compare
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.
We use YAML literals to assert the contents of complex Kubernetes DTOs, but it is time-consuming to align those literals correctly with spaces. This PR adds logic to test helpers that allows us to indent YAML and indent it with tabs.
Rather than import any internal packages in pkg/apis, I copied one test helper there.
Existing tests continue to work because their YAML is already standard and valid. I did, however, convert the YAML in
config_types_test.go
to confirm that the helper works and that tab indentation is still readable.Checklist:
Type of Changes: