Allow indented YAML in tests#4272
Merged
cbandy merged 2 commits intoCrunchyData:mainfrom Sep 10, 2025
Merged
Conversation
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 | ||
| `)) |
Member
Author
There was a problem hiding this comment.
📝 Here's a diff between left-justified spaces and tabs indented relevant to nearby Go code.
benjaminjb
reviewed
Sep 8, 2025
c7baa8b to
5080935
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.
Member
Author
|
squashed |
benjaminjb
approved these changes
Sep 10, 2025
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.
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.goto confirm that the helper works and that tab indentation is still readable.Checklist:
Type of Changes: