test: render sloth_version golden label with YAML-correct quoting#826
Open
robbat2 wants to merge 1 commit into
Open
test: render sloth_version golden label with YAML-correct quoting#826robbat2 wants to merge 1 commit into
robbat2 wants to merge 1 commit into
Conversation
The Prometheus generate integration tests and the library use-case tests both
substitute the build version (from `git describe --tags --always`) into shared
golden .tpl files. When no tag is reachable that resolves to the bare short git
SHA, which is all decimal digits ~3.7% of the time (e.g. 6950793). Sloth's YAML
serializers quote such a value ("6950793") so it round-trips as a string, but
the templates emitted it unquoted, so the assertion failed only on those
commits.
Add a shared `yamlValue` template helper (testutils.GoldenTemplateFuncs) that
marshals the version through yaml.v2 — matching both the Prometheus and k8s
serializers — and use it for the sloth_version label from both test consumers.
The comment line stays raw. The tests now pass for numeric SHAs, hex SHAs, and
semver-style versions alike.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
The Prometheus generate integration tests and the library use-case tests both substitute the build version (from
git describe --tags --always) into shared golden .tpl files. When no tag is reachable that resolves to the bare short git SHA, which is all decimal digits ~3.7% of the time (e.g. 6950793). Sloth's YAML serializers quote such a value ("6950793") so it round-trips as a string, but the templates emitted it unquoted, so the assertion failed only on those commits.Add a shared
yamlValuetemplate helper (testutils.GoldenTemplateFuncs) that marshals the version through yaml.v2 — matching both the Prometheus and k8s serializers — and use it for the sloth_version label from both test consumers. The comment line stays raw. The tests now pass for numeric SHAs, hex SHAs, and semver-style versions alike.