Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Mar 7, 2024
1 parent 06e9ca4 commit b210b0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions cmd/cscti/smokeip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"time"
Expand Down Expand Up @@ -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 {
Expand All @@ -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())
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/exprhelpers/crowdsec_cti_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit b210b0f

Please sign in to comment.