Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(linters): Fix findings found by testifylint: expected-actual #14229

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestConfigDuration(t *testing.T) {
p := c.Processors[0].Processor.(*reverse_dns.ReverseDNS)
require.EqualValues(t, p.CacheTTL, 3*time.Hour)
require.EqualValues(t, p.LookupTimeout, 17*time.Second)
require.Equal(t, p.MaxParallelLookups, 13)
require.Equal(t, 13, p.MaxParallelLookups)
require.True(t, p.Ordered)
}

Expand Down
9 changes: 5 additions & 4 deletions plugins/common/opcua/input/input_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ import (
"time"

"github.com/gopcua/opcua/ua"
"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config"
"github.com/influxdata/telegraf/metric"
"github.com/influxdata/telegraf/plugins/common/opcua"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"
)

func TestTagsSliceToMap(t *testing.T) {
m, err := tagsSliceToMap([][]string{{"foo", "bar"}, {"baz", "bat"}})
require.NoError(t, err)
require.Len(t, m, 2)
require.Equal(t, m["foo"], "bar")
require.Equal(t, m["baz"], "bat")
require.Equal(t, "bar", m["foo"])
require.Equal(t, "bat", m["baz"])
}

func TestTagsSliceToMap_twoStrings(t *testing.T) {
Expand Down Expand Up @@ -316,7 +317,7 @@ func TestNewNodeMetricMappingIdStrInstantiated(t *testing.T) {
TagsSlice: [][]string{},
}, map[string]string{})
require.NoError(t, err)
require.Equal(t, nmm.idStr, "ns=2;s=h")
require.Equal(t, "ns=2;s=h", nmm.idStr)
}

func TestValidateNodeToAdd(t *testing.T) {
Expand Down
11 changes: 6 additions & 5 deletions plugins/inputs/beat/beat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
"os"
"testing"

"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf/testutil"
)

func Test_BeatStats(t *testing.T) {
Expand Down Expand Up @@ -177,10 +178,10 @@ func Test_BeatRequest(t *testing.T) {

data, err := os.ReadFile(jsonFilePath)
require.NoErrorf(t, err, "could not read from data file %s", jsonFilePath)
require.Equal(t, request.Host, "beat.test.local")
require.Equal(t, request.Method, "POST")
require.Equal(t, request.Header.Get("Authorization"), "Basic YWRtaW46UFdE")
require.Equal(t, request.Header.Get("X-Test"), "test-value")
require.Equal(t, "beat.test.local", request.Host)
require.Equal(t, "POST", request.Method)
require.Equal(t, "Basic YWRtaW46UFdE", request.Header.Get("Authorization"))
require.Equal(t, "test-value", request.Header.Get("X-Test"))

_, err = w.Write(data)
require.NoError(t, err, "could not write data")
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/ceph/ceph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type expectedResult struct {

func TestParseSockId(t *testing.T) {
s := parseSockID(sockFile(osdPrefix, 1), osdPrefix, sockSuffix)
require.Equal(t, s, "1")
require.Equal(t, "1", s)
}

func TestParseMonDump(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ func TestTCPDialoutMultiple(t *testing.T) {
require.NoError(t, conn.Close())

// We use the invalid dialout flags to let the server close the connection
require.Equal(t, acc.Errors, []error{errors.New("invalid dialout flags: 257"), errors.New("invalid dialout flags: 257")})
require.Equal(t, []error{errors.New("invalid dialout flags: 257"), errors.New("invalid dialout flags: 257")}, acc.Errors)

tags := map[string]string{
"path": "type:model/some/path",
Expand Down Expand Up @@ -1060,7 +1060,7 @@ func TestGRPCDialoutError(t *testing.T) {
require.True(t, err == nil || errors.Is(err, io.EOF))
c.Stop()

require.Equal(t, acc.Errors, []error{errors.New("GRPC dialout error: foobar")})
require.Equal(t, []error{errors.New("GRPC dialout error: foobar")}, acc.Errors)
}

func TestGRPCDialoutMultiple(t *testing.T) {
Expand Down Expand Up @@ -1119,7 +1119,7 @@ func TestGRPCDialoutMultiple(t *testing.T) {
c.Stop()
require.NoError(t, conn.Close())

require.Equal(t, acc.Errors, []error{errors.New("GRPC dialout error: testclose"), errors.New("GRPC dialout error: testclose")})
require.Equal(t, []error{errors.New("GRPC dialout error: testclose"), errors.New("GRPC dialout error: testclose")}, acc.Errors)

tags := map[string]string{
"path": "type:model/some/path",
Expand Down
10 changes: 5 additions & 5 deletions plugins/inputs/cloud_pubsub/cloud_pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestRunParse(t *testing.T) {
sub.messages <- msg

acc.Wait(1)
require.Equal(t, acc.NFields(), 1)
require.Equal(t, 1, acc.NFields())
metric := acc.Metrics[0]
validateTestInfluxMetric(t, metric)
}
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestRunBase64(t *testing.T) {
sub.messages <- msg

acc.Wait(1)
require.Equal(t, acc.NFields(), 1)
require.Equal(t, 1, acc.NFields())
metric := acc.Metrics[0]
validateTestInfluxMetric(t, metric)
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestRunGzipDecode(t *testing.T) {
}
sub.messages <- msg
acc.Wait(1)
require.Equal(t, acc.NFields(), 1)
require.Equal(t, 1, acc.NFields())
metric := acc.Metrics[0]
validateTestInfluxMetric(t, metric)
}
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestRunInvalidMessages(t *testing.T) {
// Make sure we acknowledged message so we don't receive it again.
testTracker.WaitForAck(1)

require.Equal(t, acc.NFields(), 0)
require.Equal(t, 0, acc.NFields())
}

func TestRunOverlongMessages(t *testing.T) {
Expand Down Expand Up @@ -249,7 +249,7 @@ func TestRunOverlongMessages(t *testing.T) {
// Make sure we acknowledged message so we don't receive it again.
testTracker.WaitForAck(1)

require.Equal(t, acc.NFields(), 0)
require.Equal(t, 0, acc.NFields())
}

func TestRunErrorInSubscriber(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/exec/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func TestExec(t *testing.T) {
var acc testutil.Accumulator
err := acc.GatherError(e.Gather)
require.NoError(t, err)
require.Equal(t, acc.NFields(), 8, "non-numeric measurements should be ignored")
require.Equal(t, 8, acc.NFields(), "non-numeric measurements should be ignored")

fields := map[string]interface{}{
"num_processes": float64(82),
Expand All @@ -125,7 +125,7 @@ func TestExecMalformed(t *testing.T) {

var acc testutil.Accumulator
require.Error(t, acc.GatherError(e.Gather))
require.Equal(t, acc.NFields(), 0, "No new points should have been added")
require.Equal(t, 0, acc.NFields(), "No new points should have been added")
}

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

var acc testutil.Accumulator
require.Error(t, acc.GatherError(e.Gather))
require.Equal(t, acc.NFields(), 0, "No new points should have been added")
require.Equal(t, 0, acc.NFields(), "No new points should have been added")
}

func TestExecCommandWithGlob(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/hddtemp/hddtemp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestFetch(t *testing.T) {
err := hddTemp.Gather(acc)

require.NoError(t, err)
require.Equal(t, acc.NFields(), 2)
require.Equal(t, 2, acc.NFields())

var tests = []struct {
fields map[string]interface{}
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestHTTPWithJSONFormat(t *testing.T) {
var metric = acc.Metrics[0]
require.Equal(t, metric.Measurement, metricName)
require.Len(t, acc.Metrics[0].Fields, 1)
require.Equal(t, acc.Metrics[0].Fields["a"], 1.2)
require.Equal(t, 1.2, acc.Metrics[0].Fields["a"])
require.Equal(t, acc.Metrics[0].Tags["url"], address)
}

Expand Down Expand Up @@ -282,7 +282,7 @@ func TestBodyAndContentEncoding(t *testing.T) {
Log: testutil.Logger{},
},
queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) {
require.Equal(t, r.Header.Get("Content-Encoding"), "gzip")
require.Equal(t, "gzip", r.Header.Get("Content-Encoding"))

gr, err := gzip.NewReader(r.Body)
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/internal/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf/selfstat"
"github.com/influxdata/telegraf/testutil"

"github.com/stretchr/testify/require"
)

func TestSelfPlugin(t *testing.T) {
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestGostats(t *testing.T) {
}

require.NotNil(t, metric)
require.Equal(t, metric.Measurement, "internal_gostats")
require.Equal(t, "internal_gostats", metric.Measurement)
require.Len(t, metric.Tags, 1)
require.Contains(t, metric.Tags, "go_version")

Expand Down
16 changes: 8 additions & 8 deletions plugins/inputs/kafka_consumer/kafka_consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ func TestInit(t *testing.T) {
name: "default config",
plugin: &KafkaConsumer{},
check: func(t *testing.T, plugin *KafkaConsumer) {
require.Equal(t, plugin.ConsumerGroup, defaultConsumerGroup)
require.Equal(t, plugin.MaxUndeliveredMessages, defaultMaxUndeliveredMessages)
require.Equal(t, plugin.config.ClientID, "Telegraf")
require.Equal(t, plugin.config.Consumer.Offsets.Initial, sarama.OffsetOldest)
require.Equal(t, plugin.config.Consumer.MaxProcessingTime, 100*time.Millisecond)
require.Equal(t, defaultConsumerGroup, plugin.ConsumerGroup)
require.Equal(t, defaultMaxUndeliveredMessages, plugin.MaxUndeliveredMessages)
require.Equal(t, "Telegraf", plugin.config.ClientID)
require.Equal(t, sarama.OffsetOldest, plugin.config.Consumer.Offsets.Initial)
require.Equal(t, 100*time.Millisecond, plugin.config.Consumer.MaxProcessingTime)
},
},
{
Expand Down Expand Up @@ -114,7 +114,7 @@ func TestInit(t *testing.T) {
Log: testutil.Logger{},
},
check: func(t *testing.T, plugin *KafkaConsumer) {
require.Equal(t, plugin.config.ClientID, "custom")
require.Equal(t, "custom", plugin.config.ClientID)
},
},
{
Expand All @@ -124,7 +124,7 @@ func TestInit(t *testing.T) {
Log: testutil.Logger{},
},
check: func(t *testing.T, plugin *KafkaConsumer) {
require.Equal(t, plugin.config.Consumer.Offsets.Initial, sarama.OffsetNewest)
require.Equal(t, sarama.OffsetNewest, plugin.config.Consumer.Offsets.Initial)
},
},
{
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestInit(t *testing.T) {
Log: testutil.Logger{},
},
check: func(t *testing.T, plugin *KafkaConsumer) {
require.Equal(t, plugin.config.Consumer.MaxProcessingTime, 1000*time.Millisecond)
require.Equal(t, 1000*time.Millisecond, plugin.config.Consumer.MaxProcessingTime)
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import (
"testing"

"github.com/Shopify/sarama"
"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf/plugins/parsers/graphite"
"github.com/influxdata/telegraf/plugins/parsers/influx"
"github.com/influxdata/telegraf/plugins/parsers/json"
"github.com/influxdata/telegraf/testutil"

"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -52,7 +51,7 @@ func TestRunParser(t *testing.T) {
in <- saramaMsg(testMsg)
acc.Wait(1)

require.Equal(t, acc.NFields(), 1)
require.Equal(t, 1, acc.NFields())
}

// Test that the parser ignores invalid messages
Expand All @@ -70,7 +69,7 @@ func TestRunParserInvalidMsg(t *testing.T) {
in <- saramaMsg(invalidMsg)
acc.WaitError(1)

require.Equal(t, acc.NFields(), 0)
require.Equal(t, 0, acc.NFields())
}

// Test that overlong messages are dropped
Expand All @@ -87,7 +86,7 @@ func TestDropOverlongMsg(t *testing.T) {
in <- saramaMsg(overlongMsg)
acc.WaitError(1)

require.Equal(t, acc.NFields(), 0)
require.Equal(t, 0, acc.NFields())
}

// Test that the parser parses kafka messages into points
Expand All @@ -107,7 +106,7 @@ func TestRunParserAndGather(t *testing.T) {

require.NoError(t, acc.GatherError(k.Gather))

require.Equal(t, acc.NFields(), 1)
require.Equal(t, 1, acc.NFields())
acc.AssertContainsFields(t, "cpu_load_short",
map[string]interface{}{"value": float64(23422)})
}
Expand All @@ -128,7 +127,7 @@ func TestRunParserAndGatherGraphite(t *testing.T) {

require.NoError(t, acc.GatherError(k.Gather))

require.Equal(t, acc.NFields(), 1)
require.Equal(t, 1, acc.NFields())
acc.AssertContainsFields(t, "cpu_load_short_graphite",
map[string]interface{}{"value": float64(23422)})
}
Expand All @@ -151,7 +150,7 @@ func TestRunParserAndGatherJSON(t *testing.T) {

require.NoError(t, acc.GatherError(k.Gather))

require.Equal(t, acc.NFields(), 2)
require.Equal(t, 2, acc.NFields())
acc.AssertContainsFields(t, "kafka_json_test",
map[string]interface{}{
"a": float64(5),
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/libvirt/libvirt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func TestLibvirt_calculateMetricNumber(t *testing.T) {
}
err := l.calculateMetricNumber()
require.NoError(t, err)
require.Equal(t, l.metricNumber, domainStatsAll)
require.Equal(t, domainStatsAll, l.metricNumber)
})
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/logparser/logparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestGrokParseLogFilesAppearLater(t *testing.T) {
acc := testutil.Accumulator{}
require.NoError(t, logparser.Start(&acc))

require.Equal(t, acc.NFields(), 0)
require.Equal(t, 0, acc.NFields())

input, err := os.ReadFile(filepath.Join(testdataDir, "test_a.log"))
require.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/mesos/mesos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,14 @@ func TestWithPathDoesNotModify(t *testing.T) {
u, err := url.Parse("http://localhost:5051")
require.NoError(t, err)
v := withPath(u, "/xyzzy")
require.Equal(t, u.String(), "http://localhost:5051")
require.Equal(t, v.String(), "http://localhost:5051/xyzzy")
require.Equal(t, "http://localhost:5051", u.String())
require.Equal(t, "http://localhost:5051/xyzzy", v.String())
}

func TestURLTagDoesNotModify(t *testing.T) {
u, err := url.Parse("http://a:b@localhost:5051?timeout=1ms")
require.NoError(t, err)
v := urlTag(u)
require.Equal(t, u.String(), "http://a:b@localhost:5051?timeout=1ms")
require.Equal(t, v, "http://localhost:5051")
require.Equal(t, "http://a:b@localhost:5051?timeout=1ms", u.String())
require.Equal(t, "http://localhost:5051", v)
}
2 changes: 1 addition & 1 deletion plugins/inputs/modbus/modbus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func TestRetryFailIllegal(t *testing.T) {
require.NoError(t, modbus.Gather(&acc))
require.Len(t, acc.Errors, 1)
require.EqualError(t, acc.FirstError(), "slave 1: modbus: exception '1' (illegal function), function '129'")
require.Equal(t, counter, 1)
require.Equal(t, 1, counter)
}

func TestCases(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/mongodb/mongodb_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func TestAddShardHostStats(t *testing.T) {
}
sort.Strings(hostsFound)
sort.Strings(expectedHosts)
require.Equal(t, hostsFound, expectedHosts)
require.Equal(t, expectedHosts, hostsFound)
}

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