From b0de760b8680a48e1cc5ecdcaad7f3ac46bd366f Mon Sep 17 00:00:00 2001 From: Flavio Castelli Date: Mon, 20 Jan 2025 14:41:04 +0100 Subject: [PATCH] test: fix linter warnings Address the warnings raised by latest version of golangci-lint Signed-off-by: Flavio Castelli --- .github/workflows/ci.yml | 2 +- .golangci.yml | 2 +- Makefile | 7 +++++-- internal/handlers/create_catalog.go | 8 +++++++- internal/handlers/scan_sbom.go | 1 + internal/storage/store_test.go | 6 +++++- 6 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 004971d..1541b6a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,5 +30,5 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@ec5d18412c0aeab7936cb16880d708ba2a64e1ae # v6.2.0 with: - version: v1.61.0 + version: v1.63.4 args: --timeout=5m diff --git a/.golangci.yml b/.golangci.yml index 9c30141..32f3b33 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -10,7 +10,7 @@ run: # Timeout for analysis, e.g. 30s, 5m. # Default: 1m - timeout: 3m + timeout: 5m # This file contains only configs which differ from defaults. # All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml diff --git a/Makefile b/Makefile index 321f6c7..642c32f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -GOLANGCI_LINT_VERSION := v1.61.0 +GOLANGCI_LINT_VERSION := v1.63.4 CONTROLLER_TOOLS_VERSION := v0.16.5 ENVTEST_VERSION := release-0.19 ENVTEST_K8S_VERSION := 1.31.0 @@ -22,7 +22,10 @@ fmt: .PHOHY: lint lint: - $(GOLANGCI_LINT) run + $(GOLANGCI_LINT) run --verbose + +clean: + $(GOLANGCI_LINT) cache clean .PHOHY: vet vet: diff --git a/internal/handlers/create_catalog.go b/internal/handlers/create_catalog.go index aaf9850..8293d5f 100644 --- a/internal/handlers/create_catalog.go +++ b/internal/handlers/create_catalog.go @@ -236,7 +236,13 @@ func (h *CreateCatalogHandler) refToPlatforms(registryClient registryclient.Clie // transportFromRegistry creates a new http.RoundTripper from the options specified in the Registry spec. func (h *CreateCatalogHandler) transportFromRegistry(registry *v1alpha1.Registry) http.RoundTripper { - transport := remote.DefaultTransport.(*http.Transport).Clone() + transport, ok := remote.DefaultTransport.(*http.Transport) + if !ok { + // should not happen + panic("remote.DefaultTransport is not an *http.Transport") + } + transport = transport.Clone() + transport.TLSClientConfig = &tls.Config{ InsecureSkipVerify: registry.Spec.Insecure, //nolint:gosec // this a user provided option } diff --git a/internal/handlers/scan_sbom.go b/internal/handlers/scan_sbom.go index 1ceb165..10b1e6e 100644 --- a/internal/handlers/scan_sbom.go +++ b/internal/handlers/scan_sbom.go @@ -36,6 +36,7 @@ func NewScanSBOMHandler(k8sClient client.Client, scheme *runtime.Scheme, workDir } } +//nolint:funlen func (h *ScanSBOMHandler) Handle(message messaging.Message) error { scanSBOMMessage, ok := message.(*messaging.ScanSBOM) if !ok { diff --git a/internal/storage/store_test.go b/internal/storage/store_test.go index cd9734f..7d41c90 100644 --- a/internal/storage/store_test.go +++ b/internal/storage/store_test.go @@ -335,7 +335,11 @@ func (suite *storeTestSuite) TestGuaranteedUpdate() { key: keyPrefix + "/default/test1", preconditions: &storage.Preconditions{}, tryUpdate: func(input runtime.Object, _ storage.ResponseMeta) (runtime.Object, *uint64, error) { - input.(*v1alpha1.SBOM).Spec.SPDX.Raw = []byte(`{"foo":"bar"}`) + sbom, ok := input.(*v1alpha1.SBOM) + if !ok { + return nil, ptr.To(uint64(0)), errors.New("input is not of type *v1alpha1.SBOM") + } + sbom.Spec.SPDX.Raw = []byte(`{"foo":"bar"}`) return input, ptr.To(uint64(0)), nil }, sbom: &v1alpha1.SBOM{