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 <benoit.tigeot@lifen.fr>
pull/30930/head
Benoit Tigeot 4 months ago
parent d4e58c54ba
commit 6df8eb3b3b
No known key found for this signature in database
GPG Key ID: 8E6D4FC8AEBDA62C

@ -115,7 +115,7 @@ func TestFindChartURL(t *testing.T) {
t.Errorf("Unexpected passcredentialsall %t", passcredentialsall) t.Errorf("Unexpected passcredentialsall %t", passcredentialsall)
} }
name = "baz" name = "foo"
version = "1.2.3" version = "1.2.3"
repoURL = "http://example.com/helm" repoURL = "http://example.com/helm"
@ -124,7 +124,7 @@ func TestFindChartURL(t *testing.T) {
t.Fatal(err) 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) t.Errorf("Unexpected URL %q", churl)
} }
if username != "" { if username != "" {

Loading…
Cancel
Save