test: fix helm test flake (#27275)

Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com>
This commit is contained in:
Blake Pettersson 2026-04-13 11:18:42 +02:00 committed by GitHub
parent de9416137d
commit bd823728ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -461,31 +461,16 @@ func TestGenerateManifest_RefOnlyShortCircuit(t *testing.T) {
// Test that calling manifest generation on source helm reference helm files that when the revision is cached it does not call ls-remote
func TestGenerateManifestsHelmWithRefs_CachedNoLsRemote(t *testing.T) {
dir := t.TempDir()
// Use os.MkdirTemp instead of t.TempDir() because the async goroutine in
// runManifestGenAsync sets directory permissions to 0o000 (via
// directoryPermissionInitializer) after GenerateManifest returns, racing
// with t.TempDir()'s implicit RemoveAll cleanup.
dir, mkErr := os.MkdirTemp("", "TestGenerateManifestsHelmWithRefs_CachedNoLsRemote")
require.NoError(t, mkErr)
repopath := dir + "/tmprepo"
cacheMocks := newCacheMocks()
t.Cleanup(func() {
cacheMocks.mockCache.StopRedisCallback()
// Best-effort: make all files writable so t.TempDir() can clean up.
// Ignore errors (e.g. git object files with restrictive permissions in CI)
// to avoid failing the test in the cleanup phase rather than the logic phase.
// We chmod *before* descending so that directories with restrictive permissions
// (e.g. git object dirs set to 0444) become accessible prior to listing their
// entries. filepath.WalkDir cannot be used here because it reads directory
// entries before calling the callback, so a dir with 0000/0444 perms would
// already fail before we get a chance to fix it.
var fixPerms func(string)
fixPerms = func(path string) {
_ = os.Chmod(path, 0o777)
entries, err := os.ReadDir(path)
if err != nil {
return
}
for _, e := range entries {
fixPerms(filepath.Join(path, e.Name()))
}
}
fixPerms(dir)
})
service := NewService(metrics.NewMetricsServer(), cacheMocks.cache, RepoServerInitConstants{ParallelismLimit: 1}, &git.NoopCredsStore{}, repopath)
var gitClient git.Client