fix: chart icon presence test

The `TestValidateChartIconPresence` test fails when run after
`TestValidateChartIconURL` as they both are using a global
variable `badChart.Icon`

```
: go test -v -test.shuffle 1 -run '^(TestValidateChartIconPresence|TestValidateChartIconURL)$' ./pkg/lint/rules/
-test.shuffle 1
=== RUN   TestValidateChartIconURL
--- PASS: TestValidateChartIconURL (0.00s)
=== RUN   TestValidateChartIconPresence
    chartfile_test.go:171: validateChartIconPresence to return a linter error, got no error
--- FAIL: TestValidateChartIconPresence (0.00s)
FAIL
FAIL    helm.sh/helm/v4/pkg/lint/rules  0.051s
FAIL

: go test -v -test.shuffle 2 -run '^(TestValidateChartIconPresence|TestValidateChartIconURL)$' ./pkg/lint/rules/
-test.shuffle 2
=== RUN   TestValidateChartIconPresence
--- PASS: TestValidateChartIconPresence (0.00s)
=== RUN   TestValidateChartIconURL
--- PASS: TestValidateChartIconURL (0.00s)
PASS
ok      helm.sh/helm/v4/pkg/lint/rules  0.050s
```

This commit:

1. Remove dependency on global variable
2. Explicitly set the state of the test object.

Signed-off-by: Rostyslav Polishchuk <rostyslavp@google.com>
pull/30783/head
Rostyslav Polishchuk 5 months ago
parent 9a670ae920
commit 1c8d1e375f

@ -166,10 +166,30 @@ func TestValidateChartSources(t *testing.T) {
}
func TestValidateChartIconPresence(t *testing.T) {
err := validateChartIconPresence(badChart)
if err == nil {
t.Errorf("validateChartIconPresence to return a linter error, got no error")
}
t.Run("Icon absent", func(t *testing.T) {
testChart := &chart.Metadata{
Icon: "",
}
err := validateChartIconPresence(testChart)
if err == nil {
t.Errorf("validateChartIconPresence to return a linter error, got no error")
} else if !strings.Contains(err.Error(), "icon is recommended") {
t.Errorf("expected %q, got %q", "icon is recommended", err.Error())
}
})
t.Run("Icon present", func(t *testing.T) {
testChart := &chart.Metadata{
Icon: "http://example.org/icon.png",
}
err := validateChartIconPresence(testChart)
if err != nil {
t.Errorf("Unexpected error: %q", err.Error())
}
})
}
func TestValidateChartIconURL(t *testing.T) {

Loading…
Cancel
Save