Skip to content

Commit

Permalink
enabling existing linting for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgheewala committed Dec 13, 2020
1 parent ae40f02 commit 4bee418
Show file tree
Hide file tree
Showing 54 changed files with 300 additions and 335 deletions.
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
run:
timeout: 1m
tests: false
tests: true
skip-dirs:
skip-files:
- ".*\\.pb\\.go"
Expand Down Expand Up @@ -94,9 +94,9 @@ linters:
- gomnd
- nestif
- nlreturn
- gochecknoinits
# TODO: enable this linters later
- goerr113
- gochecknoinits
fast: true

# output configuration options
Expand Down
4 changes: 1 addition & 3 deletions boltcycle/boltcycle_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package boltcycle

import (
"bytes"
"context"
"encoding/binary"
"io/ioutil"
Expand All @@ -22,10 +21,9 @@ type testSetup struct {
cdb *CycleDB
cycleLen int
readMovementsBacklog int
log bytes.Buffer
t *testing.T
failedDelete bool
asyncErrors chan error
failedDelete bool
readOnly bool
}

Expand Down
3 changes: 1 addition & 2 deletions clientcfg/client_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package clientcfg

import (
"context"
"errors"
"net/url"
"testing"

"context"

"github.com/signalfx/golib/v3/datapoint/dptest"
"github.com/signalfx/golib/v3/distconf"
"github.com/signalfx/golib/v3/log"
Expand Down
5 changes: 5 additions & 0 deletions datapoint/cast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ var castMetricValueTests = []CastMetricValueTest{

func TestCastMetricValue(t *testing.T) {
for _, tt := range castMetricValueTests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
gotMetricValue, err := CastMetricValue(tt.args.value)
if (err != nil) != tt.wantErr {
Expand Down Expand Up @@ -144,6 +145,7 @@ var castMetricValueWithBoolTests = append(castMetricValueTests,

func TestCastMetricValueWithBool(t *testing.T) {
for _, tt := range castMetricValueWithBoolTests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
gotMetricValue, err := CastMetricValueWithBool(tt.args.value)
if (err != nil) != tt.wantErr {
Expand Down Expand Up @@ -176,6 +178,7 @@ func TestCastFloatValue(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
gotMetricValue, err := CastFloatValue(tt.args.value)
if (err != nil) != tt.wantErr {
Expand Down Expand Up @@ -208,6 +211,7 @@ func TestCastUIntegerValue(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
gotMetricValue, err := CastUIntegerValue(tt.args.value)
if (err != nil) != tt.wantErr {
Expand Down Expand Up @@ -240,6 +244,7 @@ func TestCastIntegerValue(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
gotMetricValue, err := CastIntegerValue(tt.args.value)
if (err != nil) != tt.wantErr {
Expand Down
1 change: 0 additions & 1 deletion datapoint/datapoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func TestDatapointHelperFunctions(t *testing.T) {
}

func TestDatapointJSONDecode(t *testing.T) {

datapointInOut := func(dpIn *Datapoint) Datapoint {
var dpOut Datapoint
b, err := json.Marshal(dpIn)
Expand Down
1 change: 0 additions & 1 deletion datapoint/dplocal/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"os"
"testing"

"time"

"github.com/signalfx/golib/v3/datapoint"
Expand Down
6 changes: 2 additions & 4 deletions datapoint/dpsink/counter_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package dpsink

import (
"context"
"errors"
"sync/atomic"
"testing"
"time"

"sync/atomic"

"context"

"github.com/signalfx/golib/v3/datapoint"
"github.com/signalfx/golib/v3/datapoint/dptest"
"github.com/signalfx/golib/v3/event"
Expand Down
8 changes: 5 additions & 3 deletions datapoint/dpsink/discard_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package dpsink

import (
"context"
"testing"

. "github.com/smartystreets/goconvey/convey"
)

func TestSinkDiscard(t *testing.T) {
Convey("Discard sink should not error", t, func() {
So(Discard.AddEvents(nil, nil), ShouldBeNil)
So(Discard.AddDatapoints(nil, nil), ShouldBeNil)
So(Discard.AddSpans(nil, nil), ShouldBeNil)
ctx := context.Background()
So(Discard.AddEvents(ctx, nil), ShouldBeNil)
So(Discard.AddDatapoints(ctx, nil), ShouldBeNil)
So(Discard.AddSpans(ctx, nil), ShouldBeNil)
})
}
3 changes: 1 addition & 2 deletions datapoint/dpsink/filter_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package dpsink

import (
"context"
"runtime"
"testing"

"context"

"github.com/signalfx/golib/v3/datapoint"
"github.com/signalfx/golib/v3/datapoint/dptest"
"github.com/stretchr/testify/assert"
Expand Down
8 changes: 4 additions & 4 deletions datapoint/dpsink/logfilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,22 @@ func TestFilter(t *testing.T) {
})

Convey("Invalid POST should return an error", func() {
req, err := http.NewRequest("POST", "", strings.NewReader(`_INVALID_JSON`))
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, "", strings.NewReader(`_INVALID_JSON`))
So(err, ShouldBeNil)
rw := httptest.NewRecorder()
i.ServeHTTP(rw, req)
So(rw.Code, ShouldEqual, http.StatusBadRequest)
})

Convey("POST should change dimensions", func() {
req, err := http.NewRequest("POST", "", strings.NewReader(`{"name":"jack"}`))
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, "", strings.NewReader(`{"name":"jack"}`))
So(err, ShouldBeNil)
rw := httptest.NewRecorder()
i.ServeHTTP(rw, req)
So(rw.Code, ShouldEqual, http.StatusOK)
So(i.GetDimensions(), ShouldResemble, map[string]string{"name": "jack"})
Convey("and GET should return them", func() {
req, err := http.NewRequest("GET", "", nil)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, "", nil)
So(err, ShouldBeNil)
rw := httptest.NewRecorder()
i.ServeHTTP(rw, req)
Expand All @@ -106,7 +106,7 @@ func TestFilter(t *testing.T) {
})
})
Convey("PATCH should 404", func() {
req, err := http.NewRequest("PATCH", "", strings.NewReader(`{"name":"jack"}`))
req, err := http.NewRequestWithContext(context.Background(), http.MethodPatch, "", strings.NewReader(`{"name":"jack"}`))
So(err, ShouldBeNil)
rw := httptest.NewRecorder()
i.ServeHTTP(rw, req)
Expand Down
3 changes: 1 addition & 2 deletions datapoint/dpsink/ratelimitlogger_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package dpsink

import (
"context"
"errors"
"testing"
"time"

"context"

"github.com/signalfx/golib/v3/datapoint"
"github.com/signalfx/golib/v3/datapoint/dptest"
"github.com/signalfx/golib/v3/event"
Expand Down
4 changes: 2 additions & 2 deletions datapoint/dpsink/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func TestFromChain(t *testing.T) {
e0 := expect{count: 0}

chain := FromChain(&e2, e0.next, e1.next)
log.IfErr(log.Panic, chain.AddDatapoints(nil, []*datapoint.Datapoint{}))
log.IfErr(log.Panic, chain.AddEvents(nil, []*event.Event{}))
log.IfErr(log.Panic, chain.AddDatapoints(context.Background(), []*datapoint.Datapoint{}))
log.IfErr(log.Panic, chain.AddEvents(context.Background(), []*event.Event{}))
}

func TestIncludingDimensions(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions datapoint/dptest/basicsink_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package dptest

import (
"context"
"errors"
"testing"

"context"

"github.com/signalfx/golib/v3/datapoint"
"github.com/signalfx/golib/v3/event"
"github.com/signalfx/golib/v3/log"
Expand All @@ -26,6 +25,7 @@ func TestBasicSinkEvent(t *testing.T) {
assert.NoError(t, b.AddEvents(context.Background(), []*event.Event{}))
assert.Equal(t, 1, len(b.EventsChan))
}

func TestBasicSinkTrace(t *testing.T) {
b := NewBasicSink()
b.TracesChan = make(chan []*trace.Span, 2)
Expand Down
21 changes: 14 additions & 7 deletions dataunit/dataunit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ func Test_SizeBytes(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if got := tt.s.Bytes(); got != int64(tt.want) {
if got := tt.s.Bytes(); got != tt.want {
t.Errorf("Size.Bytes() = %v, want %v", got, tt.want)
}
})
Expand All @@ -32,10 +33,11 @@ func TestSize_Kilobytes(t *testing.T) {
{
name: "test kilobytes",
s: 1536 * Byte,
want: float64(1.5),
want: 1.5,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if got := tt.s.Kilobytes(); got != tt.want {
t.Errorf("Size.Kilobytes() = %v, want %v", got, tt.want)
Expand All @@ -53,10 +55,11 @@ func TestSize_Megabytes(t *testing.T) {
{
name: "test megabytes",
s: 1536 * Kilobyte,
want: float64(1.5),
want: 1.5,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if got := tt.s.Megabytes(); got != tt.want {
t.Errorf("Size.Megabytes() = %v, want %v", got, tt.want)
Expand All @@ -74,10 +77,11 @@ func TestSize_Gigabytes(t *testing.T) {
{
name: "test gigabytes",
s: 1536 * Megabyte,
want: float64(1.5),
want: 1.5,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if got := tt.s.Gigabytes(); got != tt.want {
t.Errorf("Size.Gigabytes() = %v, want %v", got, tt.want)
Expand All @@ -95,10 +99,11 @@ func TestSize_Terabytes(t *testing.T) {
{
name: "test terabytes",
s: 1536 * Gigabyte,
want: float64(1.5),
want: 1.5,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if got := tt.s.Terabytes(); got != tt.want {
t.Errorf("Size.Terabytes() = %v, want %v", got, tt.want)
Expand All @@ -116,10 +121,11 @@ func TestSize_Petabytes(t *testing.T) {
{
name: "test petabytes",
s: 1536 * Terabyte,
want: float64(1.5),
want: 1.5,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if got := tt.s.Petabytes(); got != tt.want {
t.Errorf("Size.Petabytes() = %v, want %v", got, tt.want)
Expand All @@ -137,10 +143,11 @@ func TestSize_Exabytes(t *testing.T) {
{
name: "test exabytes",
s: 1536 * Petabyte,
want: float64(1.5),
want: 1.5,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if got := tt.s.Exabytes(); got != tt.want {
t.Errorf("Size.Exabytes() = %v, want %v", got, tt.want)
Expand Down
17 changes: 6 additions & 11 deletions disco/disco_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ package disco

import (
"bytes"
"fmt"
"runtime"
"sort"
"strings"
"testing"

"github.com/signalfx/golib/v3/errors"

"fmt"
"sort"

"github.com/samuel/go-zookeeper/zk"
"github.com/signalfx/golib/v3/errors"
"github.com/signalfx/golib/v3/log"
"github.com/signalfx/golib/v3/zkplus"
"github.com/signalfx/golib/v3/zkplus/zktest"
Expand Down Expand Up @@ -64,7 +62,6 @@ func TestDupAdvertise(t *testing.T) {
s := zktest.New()
z, ch, _ := s.Connect()
testDupAdvertise(t, z, ch)

}

func testDupAdvertise(t *testing.T, z zktest.ZkConnSupported, ch <-chan zk.Event) {
Expand Down Expand Up @@ -171,8 +168,8 @@ func TestBadRefresh(t *testing.T) {
}
for {
runtime.Gosched()
err := errors.Tail(s.refresh(z))
if err == badForce {
err1 := errors.Tail(s.refresh(z))
if err1 == badForce {
break
}
}
Expand All @@ -194,7 +191,7 @@ func TestBadRefresh(t *testing.T) {

// Verifying that .Services() doesn't cache a bad result
delete(d1.watchedServices, "TestAdvertiseService2")
s, err = d1.Services("TestAdvertiseService2")
_, err = d1.Services("TestAdvertiseService2")
require.Error(t, err)
_, exists := d1.watchedServices["TestAdvertiseService2"]
require.False(t, exists)
Expand Down Expand Up @@ -257,7 +254,6 @@ func TestInvalidServiceJson(t *testing.T) {

_, err = d1.Services("badservice")
require.Error(t, err)

}

func TestSort(t *testing.T) {
Expand Down Expand Up @@ -376,7 +372,6 @@ func testServices(t *testing.T, z1 zktest.ZkConnSupported, ch <-chan zk.Event, z
<-onWatchChan
require.Nil(t, s.refresh(nil))
<-doneForce

}

func TestDisco_CreatePersistentEphemeralNode(t *testing.T) {
Expand Down
Loading

0 comments on commit 4bee418

Please sign in to comment.