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 <qlapon@gmail.com>
pull/32060/head
Kunal Jain 6 months ago
parent 773b9d6c04
commit a63566c6cd

@ -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)

@ -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)

Loading…
Cancel
Save