Skip to content

Commit

Permalink
test: fix linter warnings
Browse files Browse the repository at this point in the history
Address the warnings raised by latest version of golangci-lint

Signed-off-by: Flavio Castelli <fcastelli@suse.com>
  • Loading branch information
flavio committed Jan 20, 2025
1 parent 3e98b22 commit a179a27
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,7 +22,10 @@ fmt:

.PHOHY: lint
lint:
$(GOLANGCI_LINT) run
$(GOLANGCI_LINT) run --verbose

lint-clean:
$(GOLANGCI_LINT) cache clean

.PHOHY: vet
vet:
Expand Down
18 changes: 14 additions & 4 deletions internal/handlers/create_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/x509"
"encoding/base64"
"encoding/hex"
"errors"
"fmt"
"log/slog"
"net/http"
Expand Down Expand Up @@ -69,7 +70,10 @@ func (h *CreateCatalogHandler) Handle(message messaging.Message) error {

h.logger.Debug("Registry found", "registry", registry)

transport := h.transportFromRegistry(registry)
transport, err := h.transportFromRegistry(registry)
if err != nil {
return fmt.Errorf("cannot create transport for registry %s: %w", registry.Name, err)
}
registryClient := h.registryClientFactory(transport)

repositories, err := h.discoverRepositories(ctx, registryClient, registry)
Expand Down Expand Up @@ -235,8 +239,14 @@ 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()
func (h *CreateCatalogHandler) transportFromRegistry(registry *v1alpha1.Registry) (http.RoundTripper, error) {
transport, ok := remote.DefaultTransport.(*http.Transport)
if !ok {
// should not happen
return nil, errors.New("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
}
Expand All @@ -258,7 +268,7 @@ func (h *CreateCatalogHandler) transportFromRegistry(registry *v1alpha1.Registry
}
}

return transport
return transport, nil
}

// deleteObsoleteImages deletes images that are not present in the discovered registry anymore.
Expand Down
1 change: 1 addition & 0 deletions internal/handlers/scan_sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func NewScanSBOMHandler(k8sClient client.Client, scheme *runtime.Scheme, workDir
}
}

//nolint:funlen //right now this is 2 lines too long because of error handling, if it grows more we should refactor
func (h *ScanSBOMHandler) Handle(message messaging.Message) error {
scanSBOMMessage, ok := message.(*messaging.ScanSBOM)
if !ok {
Expand Down
6 changes: 5 additions & 1 deletion internal/storage/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit a179a27

Please sign in to comment.