Skip to content

Commit 9509b62

Browse files
committed
helm/repository: address invalid test
Common mistake (https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables), but due to update now properly found by `go vet`. In addition to making the test cases work in general. Signed-off-by: Hidde Beydals <hidde@hhh.computer>
1 parent 459f266 commit 9509b62

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

internal/helm/repository/oci_chart_repository_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ func TestOCIChartRepository_Get(t *testing.T) {
210210
}
211211

212212
func TestOCIChartRepository_DownloadChart(t *testing.T) {
213-
client := &mockRegistryClient{}
214213
testCases := []struct {
215214
name string
216215
url string
@@ -225,7 +224,7 @@ func TestOCIChartRepository_DownloadChart(t *testing.T) {
225224
Metadata: &chart.Metadata{Name: "chart"},
226225
URLs: []string{"oci://localhost:5000/my_repo/podinfo:1.0.0"},
227226
},
228-
expected: "oci://localhost:5000/my_repo/podinfo:1.0.0",
227+
expected: "localhost:5000/my_repo/podinfo:1.0.0",
229228
},
230229
{
231230
name: "no chart URL",
@@ -245,27 +244,29 @@ func TestOCIChartRepository_DownloadChart(t *testing.T) {
245244
}
246245

247246
for _, tc := range testCases {
247+
tc := tc
248248
t.Run(tc.name, func(t *testing.T) {
249-
g := NewWithT(t)
250249
t.Parallel()
251-
mg := OCIMockGetter{}
250+
251+
g := NewWithT(t)
252+
252253
u, err := url.Parse(tc.url)
253254
g.Expect(err).ToNot(HaveOccurred())
255+
256+
mg := OCIMockGetter{}
254257
r := OCIChartRepository{
255258
Client: &mg,
256259
URL: *u,
257260
}
258-
r.Client = &mg
259-
g.Expect(err).ToNot(HaveOccurred())
260-
g.Expect(r).ToNot(BeNil())
261+
261262
res, err := r.DownloadChart(tc.chartVersion)
262263
if tc.expectedErr {
263264
g.Expect(err).To(HaveOccurred())
264265
return
265266
}
266267

267268
g.Expect(err).ToNot(HaveOccurred())
268-
g.Expect(client.LastCalledURL).To(Equal(tc.expected))
269+
g.Expect(mg.LastCalledURL).To(Equal(tc.expected))
269270
g.Expect(res).ToNot(BeNil())
270271
g.Expect(err).ToNot(HaveOccurred())
271272
})

0 commit comments

Comments
 (0)