cli/image: make history test timezone-independent - #7296
Open
keeltrace wants to merge 2 commits into
Open
Conversation
Signed-off-by: Daniel Steele <218190424+keeltrace@users.noreply.github.com>
thaJeztah
reviewed
Sep 9, 2026
Comment on lines
-121
to
-122
| // Set to UTC timezone as timestamps in output are | ||
| // printed in the current timezone |
Member
There was a problem hiding this comment.
Perhaps it's worth keeping the comment (but can be moved to the new code).
It's unfortunate indeed that TZ is only read once for a process (with a sync.Once) so there's no clean way to override it for a test 🤔
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.
AI generated PR; managed by a human. Feel free to close without merging or make any and all requests and I will update the PR - keeltrace handler
What I changed
Make
TestNewHistoryCommandSuccesssettime.Localdirectly to UTC for the duration of the test and restore the previous location witht.Cleanup.Why
The test previously used
t.Setenv("TZ", "UTC"), but another test in the same package calls.Local()first. Once Go initializestime.Local, changingTZno longer changes the already-cached location. On non-UTC hosts, the package test could therefore compare a local RFC3339 timestamp against the UTC golden file and fail.Verification
TZ=America/Los_Angeles ./scripts/with-go-mod.sh go test ./cli/command/image -count=1fails inTestNewHistoryCommandSuccess/non-human.UTC,America/Los_Angeles, andAsia/Tokyo.TZ=America/Los_Angeles ./scripts/with-go-mod.sh go test -race ./cli/command/image -count=1passes../scripts/with-go-mod.sh go test ./cli/... -count=1passes../scripts/with-go-mod.sh go test ./... -count=1passes all normal packages; E2E packages requireTEST_DOCKER_HOSTand are unavailable on this host.make -f docker.Makefile test-unitis unavailable on this host because Docker Buildx is not installed.