From b210b0f23326a6c1a3487554155e733f047e07db Mon Sep 17 00:00:00 2001 From: marco Date: Tue, 13 Feb 2024 10:57:00 +0100 Subject: [PATCH] lint --- cmd/cscti/smokeip.go | 14 ++++++++------ pkg/exprhelpers/crowdsec_cti_test.go | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/cmd/cscti/smokeip.go b/cmd/cscti/smokeip.go index b2b050993..6c507f11c 100644 --- a/cmd/cscti/smokeip.go +++ b/cmd/cscti/smokeip.go @@ -3,6 +3,7 @@ package main import ( "context" "encoding/json" + "errors" "fmt" "os" "time" @@ -36,7 +37,8 @@ func (cli *cliSmokeIP) smokeip(ip string) error { return err } - ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() resp, err := client.GetSmokeIpWithResponse(ctx, ip) if err != nil { @@ -45,15 +47,15 @@ func (cli *cliSmokeIP) smokeip(ip string) error { switch { case resp.JSON404 != nil: - return fmt.Errorf("ip not found") + return errors.New("ip not found") case resp.JSON403 != nil: - return fmt.Errorf("forbidden") + return errors.New("forbidden") case resp.JSON500 != nil: - return fmt.Errorf("internal server error") + return errors.New("internal server error") case resp.JSON429 != nil: - return fmt.Errorf("too many requests") + return errors.New("too many requests") case resp.JSON400 != nil: - return fmt.Errorf("bad request") + return errors.New("bad request") case resp.JSON200 == nil: return fmt.Errorf("unexpected error %d", resp.StatusCode()) } diff --git a/pkg/exprhelpers/crowdsec_cti_test.go b/pkg/exprhelpers/crowdsec_cti_test.go index 44b5b29a4..81b97cb0a 100644 --- a/pkg/exprhelpers/crowdsec_cti_test.go +++ b/pkg/exprhelpers/crowdsec_cti_test.go @@ -119,7 +119,7 @@ func TestNillClient(t *testing.T) { item, err := CrowdsecCTI("1.2.3.4") assert.Equal(t, err, cti.ErrDisabled) - assert.Equal(t, item, &cti.CTIObject{}) + assert.Equal(t, &cti.CTIObject{}, item) } func TestInvalidAuth(t *testing.T) { @@ -156,7 +156,7 @@ func TestInvalidAuth(t *testing.T) { require.NoError(t, err) item, err = CrowdsecCTI("1.2.3.4") - assert.Equal(t, item, &cti.CTIObject{}) + assert.Equal(t, &cti.CTIObject{}, item) assert.False(t, CTIApiEnabled) assert.Equal(t, err, cti.ErrDisabled) } @@ -178,7 +178,7 @@ func TestNoKey(t *testing.T) { require.NoError(t, err) item, err := CrowdsecCTI("1.2.3.4") - assert.Equal(t, item, &cti.CTIObject{}) + assert.Equal(t, &cti.CTIObject{}, item) assert.False(t, CTIApiEnabled) assert.Equal(t, err, cti.ErrDisabled) }