Skip to content

Commit

Permalink
helm/repository: address invalid test
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
hiddeco committed Mar 2, 2023
1 parent 459f266 commit 9509b62
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions internal/helm/repository/oci_chart_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ func TestOCIChartRepository_Get(t *testing.T) {
}

func TestOCIChartRepository_DownloadChart(t *testing.T) {
client := &mockRegistryClient{}
testCases := []struct {
name string
url string
Expand All @@ -225,7 +224,7 @@ func TestOCIChartRepository_DownloadChart(t *testing.T) {
Metadata: &chart.Metadata{Name: "chart"},
URLs: []string{"oci://localhost:5000/my_repo/podinfo:1.0.0"},
},
expected: "oci://localhost:5000/my_repo/podinfo:1.0.0",
expected: "localhost:5000/my_repo/podinfo:1.0.0",
},
{
name: "no chart URL",
Expand All @@ -245,27 +244,29 @@ func TestOCIChartRepository_DownloadChart(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
t.Parallel()
mg := OCIMockGetter{}

g := NewWithT(t)

u, err := url.Parse(tc.url)
g.Expect(err).ToNot(HaveOccurred())

mg := OCIMockGetter{}
r := OCIChartRepository{
Client: &mg,
URL: *u,
}
r.Client = &mg
g.Expect(err).ToNot(HaveOccurred())
g.Expect(r).ToNot(BeNil())

res, err := r.DownloadChart(tc.chartVersion)
if tc.expectedErr {
g.Expect(err).To(HaveOccurred())
return
}

g.Expect(err).ToNot(HaveOccurred())
g.Expect(client.LastCalledURL).To(Equal(tc.expected))
g.Expect(mg.LastCalledURL).To(Equal(tc.expected))
g.Expect(res).ToNot(BeNil())
g.Expect(err).ToNot(HaveOccurred())
})
Expand Down

0 comments on commit 9509b62

Please sign in to comment.