From 89d2d679e630c6f95f681c90de2a011f6583977f Mon Sep 17 00:00:00 2001 From: Felix Becker Date: Tue, 21 Jun 2022 12:22:32 +0200 Subject: [PATCH] Update golangci-lint and fix linting issues update golangci-lint from version 1.43.0 to the latest linter version 1.46.2. Fixed linting issues: Remove newline from error string in internal/test/test.go and remove redundant nil / len(0) check from asMap() function in pkg/chartutil/values.go. Guard this function by a unit test. Signed-off-by: Felix Becker --- .circleci/config.yml | 2 +- internal/test/test.go | 2 +- pkg/chartutil/values.go | 2 +- pkg/chartutil/values_test.go | 16 ++++++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 7a9c4874d..49356131c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -13,7 +13,7 @@ jobs: environment: GOCACHE: "/tmp/go/cache" - GOLANGCI_LINT_VERSION: "1.43.0" + GOLANGCI_LINT_VERSION: "1.46.2" steps: - checkout diff --git a/internal/test/test.go b/internal/test/test.go index 0de3210c4..e25463f28 100644 --- a/internal/test/test.go +++ b/internal/test/test.go @@ -79,7 +79,7 @@ func compare(actual []byte, filename string) error { } expected = normalize(expected) if !bytes.Equal(expected, actual) { - return errors.Errorf("does not match golden file %s\n\nWANT:\n'%s'\n\nGOT:\n'%s'\n", filename, expected, actual) + return errors.Errorf("does not match golden file %s\n\nWANT:\n'%s'\n\nGOT:\n'%s'", filename, expected, actual) } return nil } diff --git a/pkg/chartutil/values.go b/pkg/chartutil/values.go index e1cdf4642..97bf44217 100644 --- a/pkg/chartutil/values.go +++ b/pkg/chartutil/values.go @@ -68,7 +68,7 @@ func (v Values) Table(name string) (Values, error) { // // It protects against nil map panics. func (v Values) AsMap() map[string]interface{} { - if v == nil || len(v) == 0 { + if len(v) == 0 { return map[string]interface{}{} } return v diff --git a/pkg/chartutil/values_test.go b/pkg/chartutil/values_test.go index c95fa503a..fa6efd7aa 100644 --- a/pkg/chartutil/values_test.go +++ b/pkg/chartutil/values_test.go @@ -25,6 +25,22 @@ import ( "helm.sh/helm/v3/pkg/chart" ) +func TestAsMap(t *testing.T) { + var nilValues Values + asMap := nilValues.AsMap() + if asMap == nil { + t.Error("nilValues.AsMap() must not be nil") + } + asMap["foo"] = "bar" + nilValuesPtr := &nilValues + nilPtrAsMap := nilValuesPtr.AsMap() + if nilPtrAsMap == nil { + t.Error("nilValuesPtr.AsMap() must not be nil") + } + nilPtrAsMap["foo"] = "bar" + +} + func TestReadValues(t *testing.T) { doc := `# Test YAML parse poet: "Coleridge"