Skip to content

Commit

Permalink
Enable new linters and fix related warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaasuni committed Oct 24, 2023
1 parent a63e7ff commit 5680d6c
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 118 deletions.
213 changes: 112 additions & 101 deletions .golangci.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ branches:
- develop

go:
- '1.18'
- '1.21'

services:
- docker
Expand Down
5 changes: 2 additions & 3 deletions internal/cli/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cli

import (
"context"
"errors"
"net"
"sync"
"testing"
Expand Down Expand Up @@ -108,10 +107,10 @@ func Test_bind(t *testing.T) {
require.Error(t, err, "bind() error = %v, wantErr %v", err, tt.wantErr)
}
if tt.wantTimeoutErr {
require.True(t, errors.Is(err, context.DeadlineExceeded),
require.ErrorIs(t, err, context.DeadlineExceeded,
"bind() error = %v, wantErr %v", err, context.DeadlineExceeded)
} else {
require.False(t, errors.Is(err, context.DeadlineExceeded), "bind() unexpected timeout error")
require.NotErrorIs(t, err, context.DeadlineExceeded, "bind() unexpected timeout error")
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func Test_appConfig_SetDefaults(t *testing.T) {
c.SetDefaults(v)

require.True(t, v.GetBool("enabled"))
require.Equal(t, 5, len(v.AllKeys()))
require.Len(t, v.AllKeys(), 5)
}

func getValidTestConfig() appConfig {
Expand Down
2 changes: 1 addition & 1 deletion internal/httphandler/httphandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestHTTPHandler_BindHTTP(t *testing.T) {
mtr := metrics.New()
h := &HTTPHandler{mtr}
got := h.BindHTTP(testutil.Context())
require.Equal(t, 1, len(got))
require.Len(t, got, 1)
}

func TestHTTPHandler_handleStats(t *testing.T) {
Expand Down
22 changes: 11 additions & 11 deletions internal/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestSetUptime(t *testing.T) {

m.SetUptime(v)
i := testutil.ToFloat64(m.collectorUptime)
require.Equal(t, float64(v), i)
require.InDelta(t, float64(v), i, 0.001)
}

func TestSetMemoryTotal(t *testing.T) {
Expand All @@ -45,7 +45,7 @@ func TestSetMemoryTotal(t *testing.T) {

m.SetMemoryTotal(v)
i := testutil.ToFloat64(m.collectorMemoryTotal)
require.Equal(t, float64(v), i)
require.InDelta(t, float64(v), i, 0.001)
}

func TestSetMemoryFree(t *testing.T) {
Expand All @@ -57,7 +57,7 @@ func TestSetMemoryFree(t *testing.T) {

m.SetMemoryFree(v)
i := testutil.ToFloat64(m.collectorMemoryFree)
require.Equal(t, float64(v), i)
require.InDelta(t, float64(v), i, 0.001)
}

func TestSetLoad1(t *testing.T) {
Expand All @@ -69,7 +69,7 @@ func TestSetLoad1(t *testing.T) {

m.SetLoad1(v)
i := testutil.ToFloat64(m.collectorLoad1)
require.Equal(t, v, i)
require.InDelta(t, v, i, 0.001)
}

func TestSetLoad5(t *testing.T) {
Expand All @@ -81,7 +81,7 @@ func TestSetLoad5(t *testing.T) {

m.SetLoad5(v)
i := testutil.ToFloat64(m.collectorLoad5)
require.Equal(t, v, i)
require.InDelta(t, v, i, 0.001)
}

func TestSetLoad15(t *testing.T) {
Expand All @@ -93,7 +93,7 @@ func TestSetLoad15(t *testing.T) {

m.SetLoad15(v)
i := testutil.ToFloat64(m.collectorLoad15)
require.Equal(t, v, i)
require.InDelta(t, v, i, 0.001)
}

func TestSetTempCPU(t *testing.T) {
Expand All @@ -105,7 +105,7 @@ func TestSetTempCPU(t *testing.T) {

m.SetTempCPU(v)
i := testutil.ToFloat64(m.collectorTempCPU)
require.Equal(t, v, i)
require.InDelta(t, v, i, 0.001)
}

func TestSetDiskTotal(t *testing.T) {
Expand All @@ -117,7 +117,7 @@ func TestSetDiskTotal(t *testing.T) {

m.SetDiskTotal(v)
i := testutil.ToFloat64(m.collectorDiskTotal)
require.Equal(t, float64(v), i)
require.InDelta(t, float64(v), i, 0.001)
}

func TestSetDiskFree(t *testing.T) {
Expand All @@ -129,7 +129,7 @@ func TestSetDiskFree(t *testing.T) {

m.SetDiskFree(v)
i := testutil.ToFloat64(m.collectorDiskFree)
require.Equal(t, float64(v), i)
require.InDelta(t, float64(v), i, 0.001)
}

func TestSetNetwork(t *testing.T) {
Expand All @@ -143,8 +143,8 @@ func TestSetNetwork(t *testing.T) {
m.SetNetwork("test", rx, tx)

rc := testutil.ToFloat64(m.collectorNetworkRx)
require.Equal(t, float64(rx), rc)
require.InDelta(t, float64(rx), rc, 0.001)

tc := testutil.ToFloat64(m.collectorNetworkTx)
require.Equal(t, float64(tx), tc)
require.InDelta(t, float64(tx), tc, 0.001)
}

0 comments on commit 5680d6c

Please sign in to comment.