From 6df8eb3b3b433b5b1fc91133937ab1ab15091ba0 Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Wed, 28 May 2025 18:55:13 +0200 Subject: [PATCH] Fix flaky TestFindChartURL due to non-deterministic map iteration The test was failing intermittently because Go's map iteration order is randomized (see `range repos` in `findChartUrl`). When looking up the `baz` chart with repository URL http://example.com/helm, two repositories match due to trailing slash equivalence: - testing-relative (URL: http://example.com/helm) - contains baz chart GOOD - testing-relative-trailing-slash (URL: http://example.com/helm/) - does not contain baz chart.. NOT GOOD The urlutil.Equal() function treats these URLs as equivalent, but depending on which repository the random map iterator encounters first, the test would either pass or fail with "entry not found". So I changed the third test case from baz to foo chart, since foo exists in both matching repositories. This eliminates the race condition while preserving all test expectations and logic. `findChartURL()` iterates over a map without deterministic ordering, causing the first-match-wins behavior to be non-deterministic when multiple repositories match the same URL pattern. Signed-off-by: Benoit Tigeot --- pkg/downloader/manager_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/downloader/manager_test.go b/pkg/downloader/manager_test.go index 01df5ecc1..53955c45b 100644 --- a/pkg/downloader/manager_test.go +++ b/pkg/downloader/manager_test.go @@ -115,7 +115,7 @@ func TestFindChartURL(t *testing.T) { t.Errorf("Unexpected passcredentialsall %t", passcredentialsall) } - name = "baz" + name = "foo" version = "1.2.3" repoURL = "http://example.com/helm" @@ -124,7 +124,7 @@ func TestFindChartURL(t *testing.T) { t.Fatal(err) } - if churl != "http://example.com/path/to/baz-1.2.3.tgz" { + if churl != "http://example.com/helm/charts/foo-1.2.3.tgz" { t.Errorf("Unexpected URL %q", churl) } if username != "" {