From a63566c6cdcb6a7c8ed8c0d59ffa0dbaabcc369d Mon Sep 17 00:00:00 2001 From: Kunal Jain Date: Mon, 20 Apr 2026 19:10:03 -0700 Subject: [PATCH] test: unset SOURCE_DATE_EPOCH in TestRepeatableSave to prevent CI env interference TestRepeatableSave asserts fixed SHA values based on chart modtimes. If SOURCE_DATE_EPOCH is set in the CI environment, Save() now honors it and overrides those timestamps, producing different bytes and breaking the fixed-hash assertions. Guard against this by unsetting the env var for the duration of the test and restoring it via t.Cleanup. Signed-off-by: Kunal Jain --- internal/chart/v3/util/save_test.go | 6 ++++++ pkg/chart/v2/util/save_test.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/internal/chart/v3/util/save_test.go b/internal/chart/v3/util/save_test.go index 45732e122..dc4fd603b 100644 --- a/internal/chart/v3/util/save_test.go +++ b/internal/chart/v3/util/save_test.go @@ -269,6 +269,12 @@ func TestSaveDir(t *testing.T) { } func TestRepeatableSave(t *testing.T) { + // Guard against SOURCE_DATE_EPOCH being set in the test runner environment, + // which would override chart modtimes and invalidate the fixed SHA assertions. + if orig, ok := os.LookupEnv("SOURCE_DATE_EPOCH"); ok { + os.Unsetenv("SOURCE_DATE_EPOCH") + t.Cleanup(func() { os.Setenv("SOURCE_DATE_EPOCH", orig) }) + } tmp := t.TempDir() defer os.RemoveAll(tmp) modTime := time.Date(2021, 9, 1, 20, 34, 58, 651387237, time.UTC) diff --git a/pkg/chart/v2/util/save_test.go b/pkg/chart/v2/util/save_test.go index cfe93377b..13e478186 100644 --- a/pkg/chart/v2/util/save_test.go +++ b/pkg/chart/v2/util/save_test.go @@ -273,6 +273,12 @@ func TestSaveDir(t *testing.T) { } func TestRepeatableSave(t *testing.T) { + // Guard against SOURCE_DATE_EPOCH being set in the test runner environment, + // which would override chart modtimes and invalidate the fixed SHA assertions. + if orig, ok := os.LookupEnv("SOURCE_DATE_EPOCH"); ok { + os.Unsetenv("SOURCE_DATE_EPOCH") + t.Cleanup(func() { os.Setenv("SOURCE_DATE_EPOCH", orig) }) + } tmp := t.TempDir() defer os.RemoveAll(tmp) modTime := time.Date(2021, 9, 1, 20, 34, 58, 651387237, time.UTC)