Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
cbandy wants to merge 4 commits into CrunchyData:main
base: main
Choose a base branch
Loading
from cbandy:indent-yaml
Open

Conversation

Copy link
Member

@cbandy cbandy commented Sep 7, 2025

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:

  • Have you added an explanation of what your changes do and why you'd like them to be included?
  • Have you updated or added documentation for the change, as applicable?
  • Have you tested your changes on all related environments with successful results, as applicable?
    • Have you added automated tests?

Type of Changes:

  • Testing enhancement

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
`))
Copy link
Member Author

@cbandy cbandy Sep 7, 2025
edited
Loading

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@benjaminjb benjaminjb benjaminjb left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /