From 2777ccbe9e6e2c87e0ed1824b6873abb71f599ba Mon Sep 17 00:00:00 2001 From: Pawel Zak Date: Tue, 31 Oct 2023 23:35:28 +0100 Subject: [PATCH] chore(linters): Fix findings found by testifylint: expected-actual --- config/types_test.go | 2 +- .../common/opcua/input/input_client_test.go | 9 ++-- plugins/inputs/beat/beat_test.go | 11 +++-- plugins/inputs/ceph/ceph_test.go | 2 +- .../cisco_telemetry_mdt_test.go | 6 +-- .../inputs/cloud_pubsub/cloud_pubsub_test.go | 10 ++-- plugins/inputs/exec/exec_test.go | 6 +-- plugins/inputs/hddtemp/hddtemp_test.go | 2 +- plugins/inputs/http/http_test.go | 4 +- plugins/inputs/internal/internal_test.go | 6 +-- .../kafka_consumer/kafka_consumer_test.go | 16 +++---- .../kafka_consumer_legacy_test.go | 15 +++--- plugins/inputs/libvirt/libvirt_test.go | 2 +- plugins/inputs/logparser/logparser_test.go | 2 +- plugins/inputs/mesos/mesos_test.go | 8 ++-- plugins/inputs/modbus/modbus_test.go | 2 +- plugins/inputs/mongodb/mongodb_data_test.go | 2 +- plugins/inputs/mongodb/mongostat_test.go | 36 +++++++------- plugins/inputs/monit/monit_test.go | 4 +- .../mqtt_consumer/mqtt_consumer_test.go | 9 ++-- plugins/inputs/nats/nats_test.go | 5 +- .../inputs/neptune_apex/neptune_apex_test.go | 4 +- plugins/inputs/nginx_plus/nginx_plus_test.go | 2 +- plugins/inputs/nginx_sts/nginx_sts_test.go | 5 +- .../nginx_upstream_check_test.go | 15 +++--- plugins/inputs/nginx_vts/nginx_vts_test.go | 5 +- plugins/inputs/openntpd/openntpd_test.go | 24 +++++----- plugins/inputs/opensmtpd/opensmtpd_test.go | 4 +- plugins/inputs/p4runtime/p4runtime_test.go | 3 +- plugins/inputs/ping/ping_test.go | 4 +- .../procstat/native_finder_windows_test.go | 6 +-- plugins/inputs/prometheus/prometheus_test.go | 2 +- plugins/inputs/proxmox/proxmox_test.go | 8 ++-- plugins/inputs/raindrops/raindrops_test.go | 2 +- plugins/inputs/snmp/gosmi_test.go | 10 ++-- plugins/inputs/snmp/snmp_test.go | 12 ++--- .../inputs/stackdriver/stackdriver_test.go | 2 +- plugins/inputs/statsd/statsd_test.go | 12 ++--- plugins/inputs/unbound/unbound_test.go | 4 +- plugins/inputs/varnish/varnish_test.go | 6 +-- plugins/inputs/vsphere/vsphere_test.go | 2 +- .../win_perf_counters_test.go | 2 +- plugins/inputs/wireless/wireless_test.go | 2 +- plugins/inputs/x509_cert/x509_cert_test.go | 2 +- plugins/outputs/cratedb/cratedb_test.go | 4 +- plugins/outputs/graylog/graylog_test.go | 20 ++++---- plugins/outputs/graylog/graylog_test_linux.go | 21 ++++---- plugins/outputs/influxdb/http_test.go | 48 +++++++++---------- plugins/outputs/influxdb_v2/http_test.go | 4 +- .../outputs/stackdriver/stackdriver_test.go | 10 ++-- plugins/outputs/sumologic/sumologic_test.go | 2 +- plugins/outputs/timestream/timestream_test.go | 12 ++--- plugins/parsers/collectd/parser_test.go | 2 +- plugins/parsers/csv/parser_test.go | 44 ++++++++--------- plugins/parsers/grok/parser_test.go | 6 +-- plugins/parsers/json/parser_test.go | 2 +- plugins/parsers/xpath/parser_test.go | 2 +- plugins/processors/ifname/ttl_cache_test.go | 2 +- plugins/serializers/graphite/graphite_test.go | 2 +- plugins/serializers/msgpack/metric_test.go | 8 ++-- plugins/serializers/template/template_test.go | 5 +- 61 files changed, 248 insertions(+), 243 deletions(-) diff --git a/config/types_test.go b/config/types_test.go index 3a0d352fa1ff3..f66dc9b028b8c 100644 --- a/config/types_test.go +++ b/config/types_test.go @@ -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) } diff --git a/plugins/common/opcua/input/input_client_test.go b/plugins/common/opcua/input/input_client_test.go index dac2ab5e7ee88..a55735f616270 100644 --- a/plugins/common/opcua/input/input_client_test.go +++ b/plugins/common/opcua/input/input_client_test.go @@ -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) { @@ -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) { diff --git a/plugins/inputs/beat/beat_test.go b/plugins/inputs/beat/beat_test.go index 2ca2ffba0a149..fae8818f49f3d 100644 --- a/plugins/inputs/beat/beat_test.go +++ b/plugins/inputs/beat/beat_test.go @@ -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) { @@ -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") diff --git a/plugins/inputs/ceph/ceph_test.go b/plugins/inputs/ceph/ceph_test.go index 340f5e58d38df..a782319ea0944 100644 --- a/plugins/inputs/ceph/ceph_test.go +++ b/plugins/inputs/ceph/ceph_test.go @@ -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) { diff --git a/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt_test.go b/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt_test.go index b0ff020d9100d..3d6ab0b634b90 100644 --- a/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt_test.go +++ b/plugins/inputs/cisco_telemetry_mdt/cisco_telemetry_mdt_test.go @@ -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", @@ -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) { @@ -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", diff --git a/plugins/inputs/cloud_pubsub/cloud_pubsub_test.go b/plugins/inputs/cloud_pubsub/cloud_pubsub_test.go index 6da36a2c5f2f1..fb15b6ec47d5a 100644 --- a/plugins/inputs/cloud_pubsub/cloud_pubsub_test.go +++ b/plugins/inputs/cloud_pubsub/cloud_pubsub_test.go @@ -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) } @@ -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) } @@ -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) } @@ -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) { @@ -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) { diff --git a/plugins/inputs/exec/exec_test.go b/plugins/inputs/exec/exec_test.go index 3ac20f0feac05..edf8ef5583482 100644 --- a/plugins/inputs/exec/exec_test.go +++ b/plugins/inputs/exec/exec_test.go @@ -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), @@ -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) { @@ -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) { diff --git a/plugins/inputs/hddtemp/hddtemp_test.go b/plugins/inputs/hddtemp/hddtemp_test.go index 44be91bb28bf9..66ed52b585b14 100644 --- a/plugins/inputs/hddtemp/hddtemp_test.go +++ b/plugins/inputs/hddtemp/hddtemp_test.go @@ -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{} diff --git a/plugins/inputs/http/http_test.go b/plugins/inputs/http/http_test.go index 4eff3eee390d0..94ebefd6ab0bb 100644 --- a/plugins/inputs/http/http_test.go +++ b/plugins/inputs/http/http_test.go @@ -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) } @@ -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) diff --git a/plugins/inputs/internal/internal_test.go b/plugins/inputs/internal/internal_test.go index d5c3d79581c1d..b5f539ece6aa4 100644 --- a/plugins/inputs/internal/internal_test.go +++ b/plugins/inputs/internal/internal_test.go @@ -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) { @@ -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") diff --git a/plugins/inputs/kafka_consumer/kafka_consumer_test.go b/plugins/inputs/kafka_consumer/kafka_consumer_test.go index 3e40ad5ed8d6b..2498b35adf2e7 100644 --- a/plugins/inputs/kafka_consumer/kafka_consumer_test.go +++ b/plugins/inputs/kafka_consumer/kafka_consumer_test.go @@ -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) }, }, { @@ -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) }, }, { @@ -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) }, }, { @@ -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) }, }, } diff --git a/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy_test.go b/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy_test.go index 740a9dced2974..1aeeefc4d7909 100644 --- a/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy_test.go +++ b/plugins/inputs/kafka_consumer_legacy/kafka_consumer_legacy_test.go @@ -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 ( @@ -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 @@ -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 @@ -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 @@ -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)}) } @@ -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)}) } @@ -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), diff --git a/plugins/inputs/libvirt/libvirt_test.go b/plugins/inputs/libvirt/libvirt_test.go index a080db6248510..eb137a031b655 100644 --- a/plugins/inputs/libvirt/libvirt_test.go +++ b/plugins/inputs/libvirt/libvirt_test.go @@ -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) }) } diff --git a/plugins/inputs/logparser/logparser_test.go b/plugins/inputs/logparser/logparser_test.go index 5ce5cc8fa7872..858a7cecc240f 100644 --- a/plugins/inputs/logparser/logparser_test.go +++ b/plugins/inputs/logparser/logparser_test.go @@ -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) diff --git a/plugins/inputs/mesos/mesos_test.go b/plugins/inputs/mesos/mesos_test.go index 65f399a97c964..45a36cfb63bee 100644 --- a/plugins/inputs/mesos/mesos_test.go +++ b/plugins/inputs/mesos/mesos_test.go @@ -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) } diff --git a/plugins/inputs/modbus/modbus_test.go b/plugins/inputs/modbus/modbus_test.go index 00d715b34536a..419ba6795674a 100644 --- a/plugins/inputs/modbus/modbus_test.go +++ b/plugins/inputs/modbus/modbus_test.go @@ -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) { diff --git a/plugins/inputs/mongodb/mongodb_data_test.go b/plugins/inputs/mongodb/mongodb_data_test.go index af267283621e3..e8dc0ce82d708 100644 --- a/plugins/inputs/mongodb/mongodb_data_test.go +++ b/plugins/inputs/mongodb/mongodb_data_test.go @@ -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) { diff --git a/plugins/inputs/mongodb/mongostat_test.go b/plugins/inputs/mongodb/mongostat_test.go index 47ba058847e07..3b8ded4ced4c8 100644 --- a/plugins/inputs/mongodb/mongostat_test.go +++ b/plugins/inputs/mongodb/mongostat_test.go @@ -53,12 +53,12 @@ func TestLatencyStats(t *testing.T) { 60, ) - require.Equal(t, sl.CommandLatency, int64(0)) - require.Equal(t, sl.ReadLatency, int64(0)) - require.Equal(t, sl.WriteLatency, int64(0)) - require.Equal(t, sl.CommandOpsCnt, int64(0)) - require.Equal(t, sl.ReadOpsCnt, int64(0)) - require.Equal(t, sl.WriteOpsCnt, int64(0)) + require.Equal(t, int64(0), sl.CommandLatency) + require.Equal(t, int64(0), sl.ReadLatency) + require.Equal(t, int64(0), sl.WriteLatency) + require.Equal(t, int64(0), sl.CommandOpsCnt) + require.Equal(t, int64(0), sl.ReadOpsCnt) + require.Equal(t, int64(0), sl.WriteOpsCnt) } func TestLatencyStatsDiffZero(t *testing.T) { @@ -122,12 +122,12 @@ func TestLatencyStatsDiffZero(t *testing.T) { 60, ) - require.Equal(t, sl.CommandLatency, int64(0)) - require.Equal(t, sl.ReadLatency, int64(0)) - require.Equal(t, sl.WriteLatency, int64(0)) - require.Equal(t, sl.CommandOpsCnt, int64(0)) - require.Equal(t, sl.ReadOpsCnt, int64(0)) - require.Equal(t, sl.WriteOpsCnt, int64(0)) + require.Equal(t, int64(0), sl.CommandLatency) + require.Equal(t, int64(0), sl.ReadLatency) + require.Equal(t, int64(0), sl.WriteLatency) + require.Equal(t, int64(0), sl.CommandOpsCnt) + require.Equal(t, int64(0), sl.ReadOpsCnt) + require.Equal(t, int64(0), sl.WriteOpsCnt) } func TestLatencyStatsDiff(t *testing.T) { @@ -191,12 +191,12 @@ func TestLatencyStatsDiff(t *testing.T) { 60, ) - require.Equal(t, sl.CommandLatency, int64(59177981552)) - require.Equal(t, sl.ReadLatency, int64(2255946760057)) - require.Equal(t, sl.WriteLatency, int64(494479456987)) - require.Equal(t, sl.CommandOpsCnt, int64(1019152861)) - require.Equal(t, sl.ReadOpsCnt, int64(4189049884)) - require.Equal(t, sl.WriteOpsCnt, int64(1691021287)) + require.Equal(t, int64(59177981552), sl.CommandLatency) + require.Equal(t, int64(2255946760057), sl.ReadLatency) + require.Equal(t, int64(494479456987), sl.WriteLatency) + require.Equal(t, int64(1019152861), sl.CommandOpsCnt) + require.Equal(t, int64(4189049884), sl.ReadOpsCnt) + require.Equal(t, int64(1691021287), sl.WriteOpsCnt) } func TestLocksStatsNilWhenLocksMissingInOldStat(t *testing.T) { diff --git a/plugins/inputs/monit/monit_test.go b/plugins/inputs/monit/monit_test.go index 9ec38d7640b24..7538a997e3b8f 100644 --- a/plugins/inputs/monit/monit_test.go +++ b/plugins/inputs/monit/monit_test.go @@ -591,7 +591,7 @@ func TestInvalidUsernameOrPassword(t *testing.T) { return } - require.Equal(t, r.URL.Path, "/_status", "Cannot handle request") + require.Equal(t, "/_status", r.URL.Path, "Cannot handle request") http.ServeFile(w, r, "testdata/response_servicetype_0.xml") })) @@ -618,7 +618,7 @@ func TestNoUsernameOrPasswordConfiguration(t *testing.T) { return } - require.Equal(t, r.URL.Path, "/_status", "Cannot handle request") + require.Equal(t, "/_status", r.URL.Path, "Cannot handle request") http.ServeFile(w, r, "testdata/response_servicetype_0.xml") })) diff --git a/plugins/inputs/mqtt_consumer/mqtt_consumer_test.go b/plugins/inputs/mqtt_consumer/mqtt_consumer_test.go index 857bcad465922..f01cf986832ca 100644 --- a/plugins/inputs/mqtt_consumer/mqtt_consumer_test.go +++ b/plugins/inputs/mqtt_consumer/mqtt_consumer_test.go @@ -6,10 +6,11 @@ import ( "time" mqtt "github.com/eclipse/paho.mqtt.golang" + "github.com/stretchr/testify/require" + "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/parsers/influx" "github.com/influxdata/telegraf/testutil" - "github.com/stretchr/testify/require" ) type FakeClient struct { @@ -527,7 +528,7 @@ func TestAddRouteCalledForEachTopic(t *testing.T) { plugin.Stop() - require.Equal(t, client.addRouteCallCount, 2) + require.Equal(t, 2, client.addRouteCallCount) } func TestSubscribeCalledIfNoSession(t *testing.T) { @@ -558,7 +559,7 @@ func TestSubscribeCalledIfNoSession(t *testing.T) { plugin.Stop() - require.Equal(t, client.subscribeCallCount, 1) + require.Equal(t, 1, client.subscribeCallCount) } func TestSubscribeNotCalledIfSession(t *testing.T) { @@ -589,5 +590,5 @@ func TestSubscribeNotCalledIfSession(t *testing.T) { plugin.Stop() - require.Equal(t, client.subscribeCallCount, 0) + require.Equal(t, 0, client.subscribeCallCount) } diff --git a/plugins/inputs/nats/nats_test.go b/plugins/inputs/nats/nats_test.go index 906bf14e90ef5..588a958e882c6 100644 --- a/plugins/inputs/nats/nats_test.go +++ b/plugins/inputs/nats/nats_test.go @@ -8,8 +8,9 @@ import ( "net/http/httptest" "testing" - "github.com/influxdata/telegraf/testutil" "github.com/stretchr/testify/require" + + "github.com/influxdata/telegraf/testutil" ) var sampleVarz = ` @@ -70,7 +71,7 @@ func TestMetricsCorrect(t *testing.T) { var acc testutil.Accumulator srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - require.Equal(t, r.URL.Path, "/varz", "Cannot handle request") + require.Equal(t, "/varz", r.URL.Path, "Cannot handle request") rsp := sampleVarz _, err := fmt.Fprintln(w, rsp) diff --git a/plugins/inputs/neptune_apex/neptune_apex_test.go b/plugins/inputs/neptune_apex/neptune_apex_test.go index 29a1c6473e2ec..b77e8ac1edb12 100644 --- a/plugins/inputs/neptune_apex/neptune_apex_test.go +++ b/plugins/inputs/neptune_apex/neptune_apex_test.go @@ -370,7 +370,7 @@ func TestParseXML(t *testing.T) { } // No error case require.NoErrorf(t, err, "expected no error but got: %v", err) - require.Equalf(t, len(acc.Errors) > 0, test.wantAccErr, + require.Equalf(t, test.wantAccErr, len(acc.Errors) > 0, "Accumulator errors. got=%v, want=%t", acc.Errors, test.wantAccErr) testutil.RequireMetricsEqual(t, acc.GetTelegrafMetrics(), test.wantMetrics) @@ -511,7 +511,7 @@ func TestFindProbe(t *testing.T) { t.Run(test.name, func(t *testing.T) { t.Parallel() index := findProbe(test.probeName, fakeProbes) - require.Equalf(t, index, test.wantIndex, "probe index mismatch; got=%d, want %d", index, test.wantIndex) + require.Equalf(t, test.wantIndex, index, "probe index mismatch; got=%d, want %d", index, test.wantIndex) }) } } diff --git a/plugins/inputs/nginx_plus/nginx_plus_test.go b/plugins/inputs/nginx_plus/nginx_plus_test.go index 24aa708d567d1..cac4676b0dffd 100644 --- a/plugins/inputs/nginx_plus/nginx_plus_test.go +++ b/plugins/inputs/nginx_plus/nginx_plus_test.go @@ -253,7 +253,7 @@ func TestNginxPlusGeneratesMetrics(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var rsp string - require.Equal(t, r.URL.Path, "/status", "Cannot handle request") + require.Equal(t, "/status", r.URL.Path, "Cannot handle request") rsp = sampleStatusResponse w.Header()["Content-Type"] = []string{"application/json"} diff --git a/plugins/inputs/nginx_sts/nginx_sts_test.go b/plugins/inputs/nginx_sts/nginx_sts_test.go index 9ebb5f91ad9d8..121036167696a 100644 --- a/plugins/inputs/nginx_sts/nginx_sts_test.go +++ b/plugins/inputs/nginx_sts/nginx_sts_test.go @@ -8,8 +8,9 @@ import ( "net/url" "testing" - "github.com/influxdata/telegraf/testutil" "github.com/stretchr/testify/require" + + "github.com/influxdata/telegraf/testutil" ) const sampleStatusResponse = ` @@ -166,7 +167,7 @@ func TestNginxPlusGeneratesMetrics(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var rsp string - require.Equal(t, r.URL.Path, "/status", "Cannot handle request") + require.Equal(t, "/status", r.URL.Path, "Cannot handle request") rsp = sampleStatusResponse w.Header()["Content-Type"] = []string{"application/json"} diff --git a/plugins/inputs/nginx_upstream_check/nginx_upstream_check_test.go b/plugins/inputs/nginx_upstream_check/nginx_upstream_check_test.go index 353619b362228..e12bb1e2ccbe3 100644 --- a/plugins/inputs/nginx_upstream_check/nginx_upstream_check_test.go +++ b/plugins/inputs/nginx_upstream_check/nginx_upstream_check_test.go @@ -6,8 +6,9 @@ import ( "net/http/httptest" "testing" - "github.com/influxdata/telegraf/testutil" "github.com/stretchr/testify/require" + + "github.com/influxdata/telegraf/testutil" ) const sampleStatusResponse = ` @@ -45,7 +46,7 @@ func TestNginxUpstreamCheckData(test *testing.T) { testServer := httptest.NewServer(http.HandlerFunc(func(responseWriter http.ResponseWriter, request *http.Request) { var response string - require.Equal(test, request.URL.Path, "/status", "Cannot handle request") + require.Equal(test, "/status", request.URL.Path, "Cannot handle request") response = sampleStatusResponse responseWriter.Header()["Content-Type"] = []string{"application/json"} @@ -102,7 +103,7 @@ func TestNginxUpstreamCheckRequest(test *testing.T) { testServer := httptest.NewServer(http.HandlerFunc(func(responseWriter http.ResponseWriter, request *http.Request) { var response string - require.Equal(test, request.URL.Path, "/status", "Cannot handle request") + require.Equal(test, "/status", request.URL.Path, "Cannot handle request") response = sampleStatusResponse responseWriter.Header()["Content-Type"] = []string{"application/json"} @@ -110,10 +111,10 @@ func TestNginxUpstreamCheckRequest(test *testing.T) { _, err := fmt.Fprintln(responseWriter, response) require.NoError(test, err) - require.Equal(test, request.Method, "POST") - require.Equal(test, request.Header.Get("X-Test"), "test-value") - require.Equal(test, request.Header.Get("Authorization"), "Basic dXNlcjpwYXNzd29yZA==") - require.Equal(test, request.Host, "status.local") + require.Equal(test, "POST", request.Method) + require.Equal(test, "test-value", request.Header.Get("X-Test")) + require.Equal(test, "Basic dXNlcjpwYXNzd29yZA==", request.Header.Get("Authorization")) + require.Equal(test, "status.local", request.Host) })) defer testServer.Close() diff --git a/plugins/inputs/nginx_vts/nginx_vts_test.go b/plugins/inputs/nginx_vts/nginx_vts_test.go index 589bc634f9358..cb4567947d47e 100644 --- a/plugins/inputs/nginx_vts/nginx_vts_test.go +++ b/plugins/inputs/nginx_vts/nginx_vts_test.go @@ -8,8 +8,9 @@ import ( "net/url" "testing" - "github.com/influxdata/telegraf/testutil" "github.com/stretchr/testify/require" + + "github.com/influxdata/telegraf/testutil" ) const sampleStatusResponse = ` @@ -203,7 +204,7 @@ func TestNginxPlusGeneratesMetrics(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var rsp string - require.Equal(t, r.URL.Path, "/status", "Cannot handle request") + require.Equal(t, "/status", r.URL.Path, "Cannot handle request") rsp = sampleStatusResponse w.Header()["Content-Type"] = []string{"application/json"} diff --git a/plugins/inputs/openntpd/openntpd_test.go b/plugins/inputs/openntpd/openntpd_test.go index ffca02b31a908..88bb206480199 100644 --- a/plugins/inputs/openntpd/openntpd_test.go +++ b/plugins/inputs/openntpd/openntpd_test.go @@ -25,9 +25,9 @@ func TestParseSimpleOutput(t *testing.T) { require.NoError(t, err) require.True(t, acc.HasMeasurement("openntpd")) - require.Equal(t, acc.NMetrics(), uint64(1)) + require.Equal(t, uint64(1), acc.NMetrics()) - require.Equal(t, acc.NFields(), 7) + require.Equal(t, 7, acc.NFields()) firstpeerfields := map[string]interface{}{ "wt": int64(1), @@ -56,9 +56,9 @@ func TestParseSimpleOutputwithStatePrefix(t *testing.T) { require.NoError(t, err) require.True(t, acc.HasMeasurement("openntpd")) - require.Equal(t, acc.NMetrics(), uint64(1)) + require.Equal(t, uint64(1), acc.NMetrics()) - require.Equal(t, acc.NFields(), 7) + require.Equal(t, 7, acc.NFields()) firstpeerfields := map[string]interface{}{ "wt": int64(1), @@ -88,9 +88,9 @@ func TestParseSimpleOutputInvalidPeer(t *testing.T) { require.NoError(t, err) require.True(t, acc.HasMeasurement("openntpd")) - require.Equal(t, acc.NMetrics(), uint64(1)) + require.Equal(t, uint64(1), acc.NMetrics()) - require.Equal(t, acc.NFields(), 4) + require.Equal(t, 4, acc.NFields()) firstpeerfields := map[string]interface{}{ "wt": int64(1), @@ -116,9 +116,9 @@ func TestParseSimpleOutputServersDNSError(t *testing.T) { require.NoError(t, err) require.True(t, acc.HasMeasurement("openntpd")) - require.Equal(t, acc.NMetrics(), uint64(1)) + require.Equal(t, uint64(1), acc.NMetrics()) - require.Equal(t, acc.NFields(), 4) + require.Equal(t, 4, acc.NFields()) firstpeerfields := map[string]interface{}{ "next": int64(2), @@ -158,9 +158,9 @@ func TestParseSimpleOutputServerDNSError(t *testing.T) { require.NoError(t, err) require.True(t, acc.HasMeasurement("openntpd")) - require.Equal(t, acc.NMetrics(), uint64(1)) + require.Equal(t, uint64(1), acc.NMetrics()) - require.Equal(t, acc.NFields(), 4) + require.Equal(t, 4, acc.NFields()) firstpeerfields := map[string]interface{}{ "next": int64(12), @@ -186,9 +186,9 @@ func TestParseFullOutput(t *testing.T) { require.NoError(t, err) require.True(t, acc.HasMeasurement("openntpd")) - require.Equal(t, acc.NMetrics(), uint64(20)) + require.Equal(t, uint64(20), acc.NMetrics()) - require.Equal(t, acc.NFields(), 113) + require.Equal(t, 113, acc.NFields()) firstpeerfields := map[string]interface{}{ "wt": int64(1), diff --git a/plugins/inputs/opensmtpd/opensmtpd_test.go b/plugins/inputs/opensmtpd/opensmtpd_test.go index 3b625be51cef2..47e536c728cb9 100644 --- a/plugins/inputs/opensmtpd/opensmtpd_test.go +++ b/plugins/inputs/opensmtpd/opensmtpd_test.go @@ -25,9 +25,9 @@ func TestFilterSomeStats(t *testing.T) { require.NoError(t, err) require.True(t, acc.HasMeasurement("opensmtpd")) - require.Equal(t, acc.NMetrics(), uint64(1)) + require.Equal(t, uint64(1), acc.NMetrics()) - require.Equal(t, acc.NFields(), 36) + require.Equal(t, 36, acc.NFields()) acc.AssertContainsFields(t, "opensmtpd", parsedFullOutput) } diff --git a/plugins/inputs/p4runtime/p4runtime_test.go b/plugins/inputs/p4runtime/p4runtime_test.go index fe1c3f89dfc92..3bb297e38ca4a 100644 --- a/plugins/inputs/p4runtime/p4runtime_test.go +++ b/plugins/inputs/p4runtime/p4runtime_test.go @@ -641,9 +641,8 @@ func TestFilterCounterNamesInclude(t *testing.T) { filteredCounters := filterCounters(counters, counterNamesInclude) require.Equal( t, - filteredCounters, []*p4ConfigV1.Counter{ createCounter("bar", 2, p4ConfigV1.CounterSpec_BOTH), - }, + }, filteredCounters, ) } diff --git a/plugins/inputs/ping/ping_test.go b/plugins/inputs/ping/ping_test.go index 46e1db3f657c9..205420e22519a 100644 --- a/plugins/inputs/ping/ping_test.go +++ b/plugins/inputs/ping/ping_test.go @@ -222,7 +222,7 @@ func TestArguments(t *testing.T) { for _, system := range []string{"darwin", "linux", "anything else"} { actual := p.args("www.google.com", system) - require.Equal(t, actual, expected) + require.Equal(t, expected, actual) } } @@ -405,7 +405,7 @@ func TestPingBinary(t *testing.T) { Urls: []string{"www.google.com"}, Binary: "ping6", pingHost: func(binary string, timeout float64, args ...string) (string, error) { - require.Equal(t, binary, "ping6") + require.Equal(t, "ping6", binary) return "", nil }, } diff --git a/plugins/inputs/procstat/native_finder_windows_test.go b/plugins/inputs/procstat/native_finder_windows_test.go index 2a90344fa6761..337188921cb2d 100644 --- a/plugins/inputs/procstat/native_finder_windows_test.go +++ b/plugins/inputs/procstat/native_finder_windows_test.go @@ -17,7 +17,7 @@ func TestGather_RealPatternIntegration(t *testing.T) { pids, err := pg.Pattern(`procstat`) require.NoError(t, err) fmt.Println(pids) - require.Equal(t, len(pids) > 0, true) + require.Equal(t, true, len(pids) > 0) } func TestGather_RealFullPatternIntegration(t *testing.T) { @@ -29,7 +29,7 @@ func TestGather_RealFullPatternIntegration(t *testing.T) { pids, err := pg.FullPattern(`%procstat%`) require.NoError(t, err) fmt.Println(pids) - require.Equal(t, len(pids) > 0, true) + require.Equal(t, true, len(pids) > 0) } func TestGather_RealUserIntegration(t *testing.T) { @@ -43,5 +43,5 @@ func TestGather_RealUserIntegration(t *testing.T) { pids, err := pg.UID(currentUser.Username) require.NoError(t, err) fmt.Println(pids) - require.Equal(t, len(pids) > 0, true) + require.Equal(t, true, len(pids) > 0) } diff --git a/plugins/inputs/prometheus/prometheus_test.go b/plugins/inputs/prometheus/prometheus_test.go index b3f132903fefb..2b1c372528115 100644 --- a/plugins/inputs/prometheus/prometheus_test.go +++ b/plugins/inputs/prometheus/prometheus_test.go @@ -364,7 +364,7 @@ func TestPrometheusGeneratesSummaryMetricsV2(t *testing.T) { err = acc.GatherError(p.Gather) require.NoError(t, err) - require.Equal(t, acc.TagSetValue("prometheus", "quantile"), "0") + require.Equal(t, "0", acc.TagSetValue("prometheus", "quantile")) require.True(t, acc.HasFloatField("prometheus", "go_gc_duration_seconds_sum")) require.True(t, acc.HasFloatField("prometheus", "go_gc_duration_seconds_count")) require.Equal(t, acc.TagValue("prometheus", "url"), ts.URL+"/metrics") diff --git a/plugins/inputs/proxmox/proxmox_test.go b/plugins/inputs/proxmox/proxmox_test.go index fc7eb2d83724a..9e96c87255f7d 100644 --- a/plugins/inputs/proxmox/proxmox_test.go +++ b/plugins/inputs/proxmox/proxmox_test.go @@ -65,7 +65,7 @@ func TestGetNodeSearchDomain(t *testing.T) { err := getNodeSearchDomain(px) require.NoError(t, err) - require.Equal(t, px.nodeSearchDomain, "test.example.com") + require.Equal(t, "test.example.com", px.nodeSearchDomain) } func TestGatherLxcData(t *testing.T) { @@ -75,7 +75,7 @@ func TestGatherLxcData(t *testing.T) { acc := &testutil.Accumulator{} gatherLxcData(px, acc) - require.Equal(t, acc.NFields(), 15) + require.Equal(t, 15, acc.NFields()) testFields := map[string]interface{}{ "status": "running", "uptime": int64(2078164), @@ -109,7 +109,7 @@ func TestGatherQemuData(t *testing.T) { acc := &testutil.Accumulator{} gatherQemuData(px, acc) - require.Equal(t, acc.NFields(), 15) + require.Equal(t, 15, acc.NFields()) testFields := map[string]interface{}{ "status": "running", "uptime": int64(2159739), @@ -145,5 +145,5 @@ func TestGather(t *testing.T) { require.NoError(t, err) // Results from both tests above - require.Equal(t, acc.NFields(), 30) + require.Equal(t, 30, acc.NFields()) } diff --git a/plugins/inputs/raindrops/raindrops_test.go b/plugins/inputs/raindrops/raindrops_test.go index 6da64dbb4d207..387c2defc24a7 100644 --- a/plugins/inputs/raindrops/raindrops_test.go +++ b/plugins/inputs/raindrops/raindrops_test.go @@ -49,7 +49,7 @@ func TestRaindropsGeneratesMetrics(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var rsp string - require.Equal(t, r.URL.Path, "/_raindrops", "Cannot handle request") + require.Equal(t, "/_raindrops", r.URL.Path, "Cannot handle request") rsp = sampleResponse _, err := fmt.Fprintln(w, rsp) diff --git a/plugins/inputs/snmp/gosmi_test.go b/plugins/inputs/snmp/gosmi_test.go index fb56232695c29..57ff77b15e679 100644 --- a/plugins/inputs/snmp/gosmi_test.go +++ b/plugins/inputs/snmp/gosmi_test.go @@ -267,7 +267,7 @@ func TestTableBuild_walk_noTranslate(t *testing.T) { tb, err := tbl.Build(gosmiTsc, true, tr) require.NoError(t, err) - require.Equal(t, tb.Name, "mytable") + require.Equal(t, "mytable", tb.Name) rtr1 := RTableRow{ Tags: map[string]string{ "myfield1": "foo", @@ -350,7 +350,7 @@ func TestTableBuild_walk_Translate(t *testing.T) { tb, err := tbl.Build(gosmiTsc, true, tr) require.NoError(t, err) - require.Equal(t, tb.Name, "atTable") + require.Equal(t, "atTable", tb.Name) rtr1 := RTableRow{ Tags: map[string]string{ @@ -698,7 +698,7 @@ func TestTableJoin_walkGosmi(t *testing.T) { tb, err := tbl.Build(gosmiTsc, true, tr) require.NoError(t, err) - require.Equal(t, tb.Name, "mytable") + require.Equal(t, "mytable", tb.Name) rtr1 := RTableRow{ Tags: map[string]string{ "myfield1": "instance", @@ -781,7 +781,7 @@ func TestTableOuterJoin_walkGosmi(t *testing.T) { tb, err := tbl.Build(gosmiTsc, true, tr) require.NoError(t, err) - require.Equal(t, tb.Name, "mytable") + require.Equal(t, "mytable", tb.Name) rtr1 := RTableRow{ Tags: map[string]string{ "myfield1": "instance", @@ -873,7 +873,7 @@ func TestTableJoinNoIndexAsTag_walkGosmi(t *testing.T) { tb, err := tbl.Build(gosmiTsc, true, tr) require.NoError(t, err) - require.Equal(t, tb.Name, "mytable") + require.Equal(t, "mytable", tb.Name) rtr1 := RTableRow{ Tags: map[string]string{ "myfield1": "instance", diff --git a/plugins/inputs/snmp/snmp_test.go b/plugins/inputs/snmp/snmp_test.go index 326a9d21742ed..44aec0ae99c8b 100644 --- a/plugins/inputs/snmp/snmp_test.go +++ b/plugins/inputs/snmp/snmp_test.go @@ -332,7 +332,7 @@ func TestGetSNMPConnection_v3(t *testing.T) { gsc, err := s.getConnection(0) require.NoError(t, err) gs := gsc.(snmp.GosnmpWrapper) - require.Equal(t, gs.Version, gosnmp.Version3) + require.Equal(t, gosnmp.Version3, gs.Version) sp := gs.SecurityParameters.(*gosnmp.UsmSecurityParameters) require.Equal(t, "1.2.3.4", gsc.Host()) require.EqualValues(t, 20, gs.MaxRepetitions) @@ -453,7 +453,7 @@ func TestGetSNMPConnection_v3_blumenthal(t *testing.T) { gsc, err := s.getConnection(0) require.NoError(t, err) gs := gsc.(snmp.GosnmpWrapper) - require.Equal(t, gs.Version, gosnmp.Version3) + require.Equal(t, gosnmp.Version3, gs.Version) sp := gs.SecurityParameters.(*gosnmp.UsmSecurityParameters) require.Equal(t, "1.2.3.4", gsc.Host()) require.EqualValues(t, 20, gs.MaxRepetitions) @@ -644,7 +644,7 @@ func TestTableBuild_walk(t *testing.T) { tb, err := tbl.Build(tsc, true, NewNetsnmpTranslator()) require.NoError(t, err) - require.Equal(t, tb.Name, "mytable") + require.Equal(t, "mytable", tb.Name) rtr1 := RTableRow{ Tags: map[string]string{ "myfield1": "foo", @@ -988,7 +988,7 @@ func TestTableJoin_walk(t *testing.T) { tb, err := tbl.Build(tsc, true, NewNetsnmpTranslator()) require.NoError(t, err) - require.Equal(t, tb.Name, "mytable") + require.Equal(t, "mytable", tb.Name) rtr1 := RTableRow{ Tags: map[string]string{ "myfield1": "instance", @@ -1065,7 +1065,7 @@ func TestTableOuterJoin_walk(t *testing.T) { tb, err := tbl.Build(tsc, true, NewNetsnmpTranslator()) require.NoError(t, err) - require.Equal(t, tb.Name, "mytable") + require.Equal(t, "mytable", tb.Name) rtr1 := RTableRow{ Tags: map[string]string{ "myfield1": "instance", @@ -1151,7 +1151,7 @@ func TestTableJoinNoIndexAsTag_walk(t *testing.T) { tb, err := tbl.Build(tsc, true, NewNetsnmpTranslator()) require.NoError(t, err) - require.Equal(t, tb.Name, "mytable") + require.Equal(t, "mytable", tb.Name) rtr1 := RTableRow{ Tags: map[string]string{ "myfield1": "instance", diff --git a/plugins/inputs/stackdriver/stackdriver_test.go b/plugins/inputs/stackdriver/stackdriver_test.go index 6f4eb88486a5d..98be7a0246c07 100644 --- a/plugins/inputs/stackdriver/stackdriver_test.go +++ b/plugins/inputs/stackdriver/stackdriver_test.go @@ -748,7 +748,7 @@ func TestGather(t *testing.T) { err := s.Gather(&acc) require.NoError(t, err) - require.Equalf(t, len(acc.Errors) > 0, tt.wantAccErr, + require.Equalf(t, tt.wantAccErr, len(acc.Errors) > 0, "Accumulator errors. got=%v, want=%t", acc.Errors, tt.wantAccErr) actual := []telegraf.Metric{} diff --git a/plugins/inputs/statsd/statsd_test.go b/plugins/inputs/statsd/statsd_test.go index 8c405108e33dd..61744cbdf6168 100644 --- a/plugins/inputs/statsd/statsd_test.go +++ b/plugins/inputs/statsd/statsd_test.go @@ -1284,7 +1284,7 @@ func TestParse_MeasurementsWithMultipleValues(t *testing.T) { cachedtiming, ok := sSingle.timings["metric_type=timingvalid_multiple"] require.Truef(t, ok, "Expected cached measurement with hash 'metric_type=timingvalid_multiple' not found") - require.Equalf(t, cachedtiming.name, "valid_multiple", "Expected the name to be 'valid_multiple', got %s", cachedtiming.name) + require.Equalf(t, "valid_multiple", cachedtiming.name, "Expected the name to be 'valid_multiple', got %s", cachedtiming.name) // A 0 at samplerate 0.1 will add 10 values of 0, // A 0 with invalid samplerate will add a single 0, @@ -1617,12 +1617,12 @@ func TestParse_Counters_Delete(t *testing.T) { func TestParseKeyValue(t *testing.T) { k, v := parseKeyValue("foo=bar") - require.Equalf(t, k, "foo", "Expected %s, got %s", "foo", k) - require.Equalf(t, v, "bar", "Expected %s, got %s", "bar", v) + require.Equalf(t, "foo", k, "Expected %s, got %s", "foo", k) + require.Equalf(t, "bar", v, "Expected %s, got %s", "bar", v) k2, v2 := parseKeyValue("baz") - require.Equalf(t, k2, "", "Expected %s, got %s", "", k2) - require.Equalf(t, v2, "baz", "Expected %s, got %s", "baz", v2) + require.Equalf(t, "", k2, "Expected %s, got %s", "", k2) + require.Equalf(t, "baz", v2, "Expected %s, got %s", "baz", v2) } // Test utility functions @@ -1849,7 +1849,7 @@ func TestParse_Ints(t *testing.T) { acc := &testutil.Accumulator{} require.NoError(t, s.Gather(acc)) - require.Equal(t, s.Percentiles, []Number{90.0}) + require.Equal(t, []Number{90.0}, s.Percentiles) } func TestParse_KeyValue(t *testing.T) { diff --git a/plugins/inputs/unbound/unbound_test.go b/plugins/inputs/unbound/unbound_test.go index e9994d7ebe4d6..f1ec205934b04 100644 --- a/plugins/inputs/unbound/unbound_test.go +++ b/plugins/inputs/unbound/unbound_test.go @@ -27,7 +27,7 @@ func TestParseFullOutput(t *testing.T) { require.True(t, acc.HasMeasurement("unbound")) require.Len(t, acc.Metrics, 1) - require.Equal(t, acc.NFields(), 63) + require.Equal(t, 63, acc.NFields()) acc.AssertContainsFields(t, "unbound", parsedFullOutput) } @@ -46,7 +46,7 @@ func TestParseFullOutputThreadAsTag(t *testing.T) { require.True(t, acc.HasMeasurement("unbound_threads")) require.Len(t, acc.Metrics, 2) - require.Equal(t, acc.NFields(), 63) + require.Equal(t, 63, acc.NFields()) acc.AssertContainsFields(t, "unbound", parsedFullOutputThreadAsTagMeasurementUnbound) acc.AssertContainsFields(t, "unbound_threads", parsedFullOutputThreadAsTagMeasurementUnboundThreads) diff --git a/plugins/inputs/varnish/varnish_test.go b/plugins/inputs/varnish/varnish_test.go index 6a3b305134a5a..ca45e8c4c3094 100644 --- a/plugins/inputs/varnish/varnish_test.go +++ b/plugins/inputs/varnish/varnish_test.go @@ -558,7 +558,7 @@ func TestVersions(t *testing.T) { require.Len(t, acc.Metrics, c.size) for _, m := range acc.Metrics { require.NotEmpty(t, m.Fields) - require.Equal(t, m.Measurement, "varnish") + require.Equal(t, "varnish", m.Measurement) for field := range m.Fields { require.NotContains(t, field, "reload_") } @@ -627,11 +627,11 @@ func TestVarnishAdmJson(t *testing.T) { require.NoError(t, err) activeVcl, err := getActiveVCLJson(bytes.NewBuffer(admJSON)) require.NoError(t, err) - require.Equal(t, activeVcl, "boot-123") + require.Equal(t, "boot-123", activeVcl) admJSON, err = os.ReadFile("test_data/" + "varnishadm-reload.json") require.NoError(t, err) activeVcl, err = getActiveVCLJson(bytes.NewBuffer(admJSON)) require.NoError(t, err) - require.Equal(t, activeVcl, "reload_20210723_091821_2056185") + require.Equal(t, "reload_20210723_091821_2056185", activeVcl) } diff --git a/plugins/inputs/vsphere/vsphere_test.go b/plugins/inputs/vsphere/vsphere_test.go index a6064be88d338..b933942b9e6e1 100644 --- a/plugins/inputs/vsphere/vsphere_test.go +++ b/plugins/inputs/vsphere/vsphere_test.go @@ -476,7 +476,7 @@ func TestDisconnectedServerBehavior(t *testing.T) { v.DisconnectedServersBehavior = "something else" _, err = NewEndpoint(context.Background(), v, u, v.Log) require.Error(t, err) - require.Equal(t, err.Error(), `"something else" is not a valid value for disconnected_servers_behavior`) + require.Equal(t, `"something else" is not a valid value for disconnected_servers_behavior`, err.Error()) } func testCollection(t *testing.T, excludeClusters bool) { diff --git a/plugins/inputs/win_perf_counters/win_perf_counters_test.go b/plugins/inputs/win_perf_counters/win_perf_counters_test.go index 6ed499f0d41e7..40593475db690 100644 --- a/plugins/inputs/win_perf_counters/win_perf_counters_test.go +++ b/plugins/inputs/win_perf_counters/win_perf_counters_test.go @@ -316,7 +316,7 @@ func TestCounterPathParsing(t *testing.T) { for path, vals := range counterPathsAndRes { h, o, i, c, err := extractCounterInfoFromCounterPath(path) require.NoError(t, err) - require.Equalf(t, vals, []string{h, o, i, c}, "arrays: %#v and %#v are not equal", vals, []string{o, i, c}) + require.Equalf(t, []string{h, o, i, c}, vals, "arrays: %#v and %#v are not equal", vals, []string{o, i, c}) } for _, path := range invalidCounterPaths { _, _, _, _, err := extractCounterInfoFromCounterPath(path) diff --git a/plugins/inputs/wireless/wireless_test.go b/plugins/inputs/wireless/wireless_test.go index f16c80ea6f8ad..71904c56625c7 100644 --- a/plugins/inputs/wireless/wireless_test.go +++ b/plugins/inputs/wireless/wireless_test.go @@ -52,5 +52,5 @@ func TestLoadWirelessTable(t *testing.T) { require.NoError(t, err) as := require.New(t) - as.Equal(metrics, expectedMetrics) + as.Equal(expectedMetrics, metrics) } diff --git a/plugins/inputs/x509_cert/x509_cert_test.go b/plugins/inputs/x509_cert/x509_cert_test.go index a2ebab51bd69a..46d2aeea25f42 100644 --- a/plugins/inputs/x509_cert/x509_cert_test.go +++ b/plugins/inputs/x509_cert/x509_cert_test.go @@ -260,7 +260,7 @@ func TestGatherExcludeRootCerts(t *testing.T) { require.NoError(t, sc.Gather(&acc)) require.True(t, acc.HasMeasurement("x509_cert")) - require.Equal(t, acc.NMetrics(), uint64(1)) + require.Equal(t, uint64(1), acc.NMetrics()) } func TestGatherChain(t *testing.T) { diff --git a/plugins/outputs/cratedb/cratedb_test.go b/plugins/outputs/cratedb/cratedb_test.go index 20d84f3bd5f3e..d1fdf1688308d 100644 --- a/plugins/outputs/cratedb/cratedb_test.go +++ b/plugins/outputs/cratedb/cratedb_test.go @@ -168,14 +168,14 @@ func TestEscapeValue(t *testing.T) { for _, test := range tests { got, err := escapeValue(test.Value, "_") require.NoError(t, err, "value: %#v", test.Value) - require.Equal(t, got, test.Want) + require.Equal(t, test.Want, got) } } func TestCircumventingStringEscape(t *testing.T) { value, err := escapeObject(map[string]interface{}{"a.b": "c"}, `_"`) require.NoError(t, err) - require.Equal(t, value, `{"a_""b" = 'c'}`) + require.Equal(t, `{"a_""b" = 'c'}`, value) } func Test_hashID(t *testing.T) { diff --git a/plugins/outputs/graylog/graylog_test.go b/plugins/outputs/graylog/graylog_test.go index 802befa574f49..cdeb78a60c693 100644 --- a/plugins/outputs/graylog/graylog_test.go +++ b/plugins/outputs/graylog/graylog_test.go @@ -37,15 +37,15 @@ func TestSerializer(t *testing.T) { err = json.Unmarshal([]byte(r), &obj) require.NoError(t, err) - require.Equal(t, obj["version"], "1.1") - require.Equal(t, obj["_name"], "testing") - require.Equal(t, obj["_verb"], "GET") - require.Equal(t, obj["host"], "hostname") - require.Equal(t, obj["full_message"], "full") - require.Equal(t, obj["short_message"], "short") - require.Equal(t, obj["level"], "1") - require.Equal(t, obj["facility"], "demo") - require.Equal(t, obj["line"], "42") - require.Equal(t, obj["file"], "graylog.go") + require.Equal(t, "1.1", obj["version"]) + require.Equal(t, "testing", obj["_name"]) + require.Equal(t, "GET", obj["_verb"]) + require.Equal(t, "hostname", obj["host"]) + require.Equal(t, "full", obj["full_message"]) + require.Equal(t, "short", obj["short_message"]) + require.Equal(t, "1", obj["level"]) + require.Equal(t, "demo", obj["facility"]) + require.Equal(t, "42", obj["line"]) + require.Equal(t, "graylog.go", obj["file"]) } } diff --git a/plugins/outputs/graylog/graylog_test_linux.go b/plugins/outputs/graylog/graylog_test_linux.go index 563f81ac14e39..1a50086cffa6f 100644 --- a/plugins/outputs/graylog/graylog_test_linux.go +++ b/plugins/outputs/graylog/graylog_test_linux.go @@ -16,10 +16,11 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/influxdata/telegraf/config" tlsint "github.com/influxdata/telegraf/plugins/common/tls" "github.com/influxdata/telegraf/testutil" - "github.com/stretchr/testify/require" ) func TestWriteUDP(t *testing.T) { @@ -170,14 +171,14 @@ func UDPServer(t *testing.T, wg *sync.WaitGroup, namefieldnoprefix bool) string if err != nil { return err } - require.Equal(t, obj["short_message"], "telegraf") + require.Equal(t, "telegraf", obj["short_message"]) if namefieldnoprefix { - require.Equal(t, obj["name"], "test1") + require.Equal(t, "test1", obj["name"]) } else { - require.Equal(t, obj["_name"], "test1") + require.Equal(t, "test1", obj["_name"]) } - require.Equal(t, obj["_tag1"], "value1") - require.Equal(t, obj["_value"], float64(1)) + require.Equal(t, "value1", obj["_tag1"]) + require.Equal(t, float64(1), obj["_value"]) return nil } @@ -247,10 +248,10 @@ func TCPServer(t *testing.T, wg *sync.WaitGroup, tlsConfig *tls.Config, errs cha var obj GelfObject err = json.Unmarshal(bufW.Bytes(), &obj) require.NoError(t, err) - require.Equal(t, obj["short_message"], "telegraf") - require.Equal(t, obj["_name"], "test1") - require.Equal(t, obj["_tag1"], "value1") - require.Equal(t, obj["_value"], float64(1)) + require.Equal(t, "telegraf", obj["short_message"]) + require.Equal(t, "test1", obj["_name"]) + require.Equal(t, "value1", obj["_tag1"]) + require.Equal(t, float64(1), obj["_value"]) return nil } diff --git a/plugins/outputs/influxdb/http_test.go b/plugins/outputs/influxdb/http_test.go index 0b9cfd399a862..316b007270f01 100644 --- a/plugins/outputs/influxdb/http_test.go +++ b/plugins/outputs/influxdb/http_test.go @@ -119,8 +119,8 @@ func TestHTTP_CreateDatabase(t *testing.T) { }, database: `a " b`, queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { - require.Equal(t, r.Header.Get("A"), "B") - require.Equal(t, r.Header.Get("C"), "D") + require.Equal(t, "B", r.Header.Get("A")) + require.Equal(t, "D", r.Header.Get("C")) w.WriteHeader(http.StatusOK) _, err = w.Write(successResponse) require.NoError(t, err) @@ -137,8 +137,8 @@ func TestHTTP_CreateDatabase(t *testing.T) { Database: "telegraf", }, queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { - require.Equal(t, r.Header.Get("A"), "B") - require.Equal(t, r.Header.Get("C"), "D") + require.Equal(t, "B", r.Header.Get("A")) + require.Equal(t, "D", r.Header.Get("C")) w.WriteHeader(http.StatusOK) _, err = w.Write(successResponse) require.NoError(t, err) @@ -291,7 +291,7 @@ func TestHTTP_Write(t *testing.T) { Log: testutil.Logger{}, }, queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { - require.Equal(t, r.FormValue("db"), "telegraf") + require.Equal(t, "telegraf", r.FormValue("db")) body, err := io.ReadAll(r.Body) require.NoError(t, err) require.Contains(t, string(body), "cpu value=42") @@ -324,7 +324,7 @@ func TestHTTP_Write(t *testing.T) { Log: testutil.Logger{}, }, queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { - require.Equal(t, r.Header.Get("User-Agent"), "telegraf") + require.Equal(t, "telegraf", r.Header.Get("User-Agent")) w.WriteHeader(http.StatusNoContent) }, }, @@ -362,8 +362,8 @@ func TestHTTP_Write(t *testing.T) { Log: testutil.Logger{}, }, queryHandlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { - require.Equal(t, r.Header.Get("A"), "B") - require.Equal(t, r.Header.Get("C"), "D") + require.Equal(t, "B", r.Header.Get("A")) + require.Equal(t, "D", r.Header.Get("C")) w.WriteHeader(http.StatusNoContent) }, }, @@ -581,7 +581,7 @@ func TestHTTP_WriteContentEncodingGzip(t *testing.T) { http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { case "/write": - 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) @@ -709,7 +709,7 @@ func TestHTTP_WriteDatabaseTagWorksOnRetry(t *testing.T) { case "/write": err := r.ParseForm() require.NoError(t, err) - require.Equal(t, r.Form["db"], []string{"foo"}) + require.Equal(t, []string{"foo"}, r.Form["db"]) body, err := io.ReadAll(r.Body) require.NoError(t, err) @@ -794,8 +794,8 @@ func TestDBRPTags(t *testing.T) { ), }, handlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { - require.Equal(t, r.FormValue("db"), "telegraf") - require.Equal(t, r.FormValue("rp"), "") + require.Equal(t, "telegraf", r.FormValue("db")) + require.Equal(t, "", r.FormValue("rp")) w.WriteHeader(http.StatusNoContent) }, }, @@ -817,8 +817,8 @@ func TestDBRPTags(t *testing.T) { ), }, handlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { - require.Equal(t, r.FormValue("db"), "telegraf") - require.Equal(t, r.FormValue("rp"), "foo") + require.Equal(t, "telegraf", r.FormValue("db")) + require.Equal(t, "foo", r.FormValue("rp")) w.WriteHeader(http.StatusNoContent) }, }, @@ -844,8 +844,8 @@ func TestDBRPTags(t *testing.T) { ), }, handlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { - require.Equal(t, r.FormValue("db"), "telegraf") - require.Equal(t, r.FormValue("rp"), "foo") + require.Equal(t, "telegraf", r.FormValue("db")) + require.Equal(t, "foo", r.FormValue("rp")) body, err := io.ReadAll(r.Body) require.NoError(t, err) require.Contains(t, string(body), "cpu,rp=foo value=42") @@ -873,8 +873,8 @@ func TestDBRPTags(t *testing.T) { ), }, handlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { - require.Equal(t, r.FormValue("db"), "telegraf") - require.Equal(t, r.FormValue("rp"), "foo") + require.Equal(t, "telegraf", r.FormValue("db")) + require.Equal(t, "foo", r.FormValue("rp")) w.WriteHeader(http.StatusNoContent) }, }, @@ -898,8 +898,8 @@ func TestDBRPTags(t *testing.T) { ), }, handlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { - require.Equal(t, r.FormValue("db"), "telegraf") - require.Equal(t, r.FormValue("rp"), "") + require.Equal(t, "telegraf", r.FormValue("db")) + require.Equal(t, "", r.FormValue("rp")) w.WriteHeader(http.StatusNoContent) }, }, @@ -926,8 +926,8 @@ func TestDBRPTags(t *testing.T) { ), }, handlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { - require.Equal(t, r.FormValue("db"), "telegraf") - require.Equal(t, r.FormValue("rp"), "foo") + require.Equal(t, "telegraf", r.FormValue("db")) + require.Equal(t, "foo", r.FormValue("rp")) body, err := io.ReadAll(r.Body) require.NoError(t, err) require.Contains(t, string(body), "cpu value=42") @@ -957,8 +957,8 @@ func TestDBRPTags(t *testing.T) { ), }, handlerFunc: func(t *testing.T, w http.ResponseWriter, r *http.Request) { - require.Equal(t, r.FormValue("db"), "telegraf") - require.Equal(t, r.FormValue("rp"), "foo") + require.Equal(t, "telegraf", r.FormValue("db")) + require.Equal(t, "foo", r.FormValue("rp")) body, err := io.ReadAll(r.Body) require.NoError(t, err) require.Contains(t, string(body), "cpu,rp=foo value=42") diff --git a/plugins/outputs/influxdb_v2/http_test.go b/plugins/outputs/influxdb_v2/http_test.go index 2985400e0d246..77dd23e80e652 100644 --- a/plugins/outputs/influxdb_v2/http_test.go +++ b/plugins/outputs/influxdb_v2/http_test.go @@ -71,7 +71,7 @@ func TestWrite(t *testing.T) { case "/api/v2/write": err := r.ParseForm() require.NoError(t, err) - require.Equal(t, r.Form["bucket"], []string{"foobar"}) + require.Equal(t, []string{"foobar"}, r.Form["bucket"]) body, err := io.ReadAll(r.Body) require.NoError(t, err) @@ -131,7 +131,7 @@ func TestWriteBucketTagWorksOnRetry(t *testing.T) { case "/api/v2/write": err := r.ParseForm() require.NoError(t, err) - require.Equal(t, r.Form["bucket"], []string{"foo"}) + require.Equal(t, []string{"foo"}, r.Form["bucket"]) body, err := io.ReadAll(r.Body) require.NoError(t, err) diff --git a/plugins/outputs/stackdriver/stackdriver_test.go b/plugins/outputs/stackdriver/stackdriver_test.go index 4b78d09c26df9..120d2338b35f0 100644 --- a/plugins/outputs/stackdriver/stackdriver_test.go +++ b/plugins/outputs/stackdriver/stackdriver_test.go @@ -118,8 +118,8 @@ func TestWrite(t *testing.T) { require.NoError(t, err) request := mockMetric.reqs[0].(*monitoringpb.CreateTimeSeriesRequest) - require.Equal(t, request.TimeSeries[0].Resource.Type, "global") - require.Equal(t, request.TimeSeries[0].Resource.Labels["project_id"], "projects/[PROJECT]") + require.Equal(t, "global", request.TimeSeries[0].Resource.Type) + require.Equal(t, "projects/[PROJECT]", request.TimeSeries[0].Resource.Labels["project_id"]) } func TestWriteResourceTypeAndLabels(t *testing.T) { @@ -150,9 +150,9 @@ func TestWriteResourceTypeAndLabels(t *testing.T) { require.NoError(t, err) request := mockMetric.reqs[0].(*monitoringpb.CreateTimeSeriesRequest) - require.Equal(t, request.TimeSeries[0].Resource.Type, "foo") - require.Equal(t, request.TimeSeries[0].Resource.Labels["project_id"], "projects/[PROJECT]") - require.Equal(t, request.TimeSeries[0].Resource.Labels["mylabel"], "myvalue") + require.Equal(t, "foo", request.TimeSeries[0].Resource.Type) + require.Equal(t, "projects/[PROJECT]", request.TimeSeries[0].Resource.Labels["project_id"]) + require.Equal(t, "myvalue", request.TimeSeries[0].Resource.Labels["mylabel"]) } func TestWriteTagsAsResourceLabels(t *testing.T) { diff --git a/plugins/outputs/sumologic/sumologic_test.go b/plugins/outputs/sumologic/sumologic_test.go index 52ff988cef39f..52c1c5a6495c9 100644 --- a/plugins/outputs/sumologic/sumologic_test.go +++ b/plugins/outputs/sumologic/sumologic_test.go @@ -321,7 +321,7 @@ func TestContentEncodingGzip(t *testing.T) { payload, err := io.ReadAll(body) require.NoError(t, err) - require.Equal(t, string(payload), "metric=cpu field=value 42 0\n") + require.Equal(t, "metric=cpu field=value 42 0\n", string(payload)) w.WriteHeader(http.StatusNoContent) }) diff --git a/plugins/outputs/timestream/timestream_test.go b/plugins/outputs/timestream/timestream_test.go index 12a7b34839718..5e6df4168107a 100644 --- a/plugins/outputs/timestream/timestream_test.go +++ b/plugins/outputs/timestream/timestream_test.go @@ -269,14 +269,14 @@ func TestWriteMultiMeasuresSingleTableMode(t *testing.T) { for _, r := range result { transformedRecords = append(transformedRecords, r.Records...) // Assert that we use measure name from input - require.Equal(t, *r.Records[0].MeasureName, "multi_measure_name") + require.Equal(t, "multi_measure_name", *r.Records[0].MeasureName) } // Expected 101 records require.Len(t, transformedRecords, recordCount+1, "Expected 101 records after transforming") // validate write to TS err := plugin.Write(inputs) require.NoError(t, err, "Write to Timestream failed") - require.Equal(t, mockClient.WriteRecordsRequestCount, 2, "Expected 2 WriteRecords calls") + require.Equal(t, 2, mockClient.WriteRecordsRequestCount, "Expected 2 WriteRecords calls") } func TestWriteMultiMeasuresMultiTableMode(t *testing.T) { @@ -324,7 +324,7 @@ func TestWriteMultiMeasuresMultiTableMode(t *testing.T) { require.Len(t, result, 1, "Expected 1 WriteRecordsInput requests") // Assert that we use measure name from config - require.Equal(t, *result[0].Records[0].MeasureName, "config-multi-measure-name") + require.Equal(t, "config-multi-measure-name", *result[0].Records[0].MeasureName) var transformedRecords []types.Record for _, r := range result { @@ -342,7 +342,7 @@ func TestWriteMultiMeasuresMultiTableMode(t *testing.T) { // validate successful write to TS err = plugin.Write(inputs) require.NoError(t, err, "Write to Timestream failed") - require.Equal(t, mockClient.WriteRecordsRequestCount, 1, "Expected 1 WriteRecords call") + require.Equal(t, 1, mockClient.WriteRecordsRequestCount, "Expected 1 WriteRecords call") } func TestBuildMultiMeasuresInSingleAndMultiTableMode(t *testing.T) { @@ -638,7 +638,7 @@ func TestWriteWhenRequestsGreaterThanMaxWriteGoRoutinesCount(t *testing.T) { err := plugin.Write(inputs) require.NoError(t, err, "Expected to write without any errors ") - require.Equal(t, mockClient.WriteRecordsRequestCount, maxWriteRecordsCalls, "Expected 5 calls to WriteRecords") + require.Equal(t, maxWriteRecordsCalls, mockClient.WriteRecordsRequestCount, "Expected 5 calls to WriteRecords") } func TestWriteWhenRequestsLesserThanMaxWriteGoRoutinesCount(t *testing.T) { @@ -677,7 +677,7 @@ func TestWriteWhenRequestsLesserThanMaxWriteGoRoutinesCount(t *testing.T) { err := plugin.Write(inputs) require.NoError(t, err, "Expected to write without any errors ") - require.Equal(t, mockClient.WriteRecordsRequestCount, maxWriteRecordsCalls, "Expected 5 calls to WriteRecords") + require.Equal(t, maxWriteRecordsCalls, mockClient.WriteRecordsRequestCount, "Expected 5 calls to WriteRecords") } func TestTransformMetricsSkipEmptyMetric(t *testing.T) { diff --git a/plugins/parsers/collectd/parser_test.go b/plugins/parsers/collectd/parser_test.go index e9108bac76acd..033a64c621165 100644 --- a/plugins/parsers/collectd/parser_test.go +++ b/plugins/parsers/collectd/parser_test.go @@ -112,7 +112,7 @@ func TestNewCollectdParser(t *testing.T) { ParseMultiValue: "join", } require.NoError(t, parser.Init()) - require.Equal(t, parser.popts.SecurityLevel, network.None) + require.Equal(t, network.None, parser.popts.SecurityLevel) require.NotNil(t, parser.popts.PasswordLookup) require.Nil(t, parser.popts.TypesDB) } diff --git a/plugins/parsers/csv/parser_test.go b/plugins/parsers/csv/parser_test.go index b26d46470950e..99582ee06b091 100644 --- a/plugins/parsers/csv/parser_test.go +++ b/plugins/parsers/csv/parser_test.go @@ -105,8 +105,8 @@ func TestTimestamp(t *testing.T) { metrics, err := p.Parse([]byte(testCSV)) require.NoError(t, err) - require.Equal(t, metrics[0].Time().UnixNano(), int64(1243094706000000000)) - require.Equal(t, metrics[1].Time().UnixNano(), int64(1257609906000000000)) + require.Equal(t, int64(1243094706000000000), metrics[0].Time().UnixNano()) + require.Equal(t, int64(1257609906000000000), metrics[1].Time().UnixNano()) } func TestTimestampYYYYMMDDHHmm(t *testing.T) { @@ -127,8 +127,8 @@ func TestTimestampYYYYMMDDHHmm(t *testing.T) { metrics, err := p.Parse([]byte(testCSV)) require.NoError(t, err) - require.Equal(t, metrics[0].Time().UnixNano(), int64(1243094700000000000)) - require.Equal(t, metrics[1].Time().UnixNano(), int64(1247328300000000000)) + require.Equal(t, int64(1243094700000000000), metrics[0].Time().UnixNano()) + require.Equal(t, int64(1247328300000000000), metrics[1].Time().UnixNano()) } func TestTimestampError(t *testing.T) { p := &Parser{ @@ -163,8 +163,8 @@ func TestTimestampUnixFormat(t *testing.T) { 1257609906,80,test_name2` metrics, err := p.Parse([]byte(testCSV)) require.NoError(t, err) - require.Equal(t, metrics[0].Time().UnixNano(), int64(1243094706000000000)) - require.Equal(t, metrics[1].Time().UnixNano(), int64(1257609906000000000)) + require.Equal(t, int64(1243094706000000000), metrics[0].Time().UnixNano()) + require.Equal(t, int64(1257609906000000000), metrics[1].Time().UnixNano()) } func TestTimestampUnixMSFormat(t *testing.T) { @@ -183,8 +183,8 @@ func TestTimestampUnixMSFormat(t *testing.T) { 1257609906123,80,test_name2` metrics, err := p.Parse([]byte(testCSV)) require.NoError(t, err) - require.Equal(t, metrics[0].Time().UnixNano(), int64(1243094706123000000)) - require.Equal(t, metrics[1].Time().UnixNano(), int64(1257609906123000000)) + require.Equal(t, int64(1243094706123000000), metrics[0].Time().UnixNano()) + require.Equal(t, int64(1257609906123000000), metrics[1].Time().UnixNano()) } func TestQuotedCharacter(t *testing.T) { @@ -673,8 +673,8 @@ func TestTimestampTimezone(t *testing.T) { metrics, err := p.Parse([]byte(testCSV)) require.NoError(t, err) - require.Equal(t, metrics[0].Time().UnixNano(), int64(1243094706000000000)) - require.Equal(t, metrics[1].Time().UnixNano(), int64(1257609906000000000)) + require.Equal(t, int64(1243094706000000000), metrics[0].Time().UnixNano()) + require.Equal(t, int64(1257609906000000000), metrics[1].Time().UnixNano()) } func TestEmptyMeasurementName(t *testing.T) { @@ -860,8 +860,8 @@ func TestParseMetadataSeparators(t *testing.T) { } err = p.Init() require.Error(t, err) - require.Equal(t, err.Error(), "initializing separators failed: "+ - "csv_metadata_separators required when specifying csv_metadata_rows") + require.Equal(t, "initializing separators failed: "+ + "csv_metadata_separators required when specifying csv_metadata_rows", err.Error()) p = &Parser{ ColumnNames: []string{"a", "b"}, MetadataRows: 1, @@ -871,7 +871,7 @@ func TestParseMetadataSeparators(t *testing.T) { require.NoError(t, err) require.Len(t, p.metadataSeparatorList, 4) require.Empty(t, p.MetadataTrimSet) - require.Equal(t, p.metadataSeparatorList, metadataPattern{":=", ",", "=", ":"}) + require.Equal(t, metadataPattern{":=", ",", "=", ":"}, p.metadataSeparatorList) p = &Parser{ ColumnNames: []string{"a", "b"}, MetadataRows: 1, @@ -882,7 +882,7 @@ func TestParseMetadataSeparators(t *testing.T) { require.NoError(t, err) require.Len(t, p.metadataSeparatorList, 4) require.Len(t, p.MetadataTrimSet, 3) - require.Equal(t, p.metadataSeparatorList, metadataPattern{":=", ",", ":", "="}) + require.Equal(t, metadataPattern{":=", ",", ":", "="}, p.metadataSeparatorList) } func TestParseMetadataRow(t *testing.T) { @@ -897,13 +897,13 @@ func TestParseMetadataRow(t *testing.T) { m := p.parseMetadataRow("# this is a not matching string") require.Nil(t, m) m = p.parseMetadataRow("# key1 : value1 \r\n") - require.Equal(t, m, map[string]string{"# key1 ": " value1 "}) + require.Equal(t, map[string]string{"# key1 ": " value1 "}, m) m = p.parseMetadataRow("key2=1234\n") - require.Equal(t, m, map[string]string{"key2": "1234"}) + require.Equal(t, map[string]string{"key2": "1234"}, m) m = p.parseMetadataRow(" file created : 2021-10-08T12:34:18+10:00 \r\n") - require.Equal(t, m, map[string]string{" file created ": " 2021-10-08T12:34:18+10:00 "}) + require.Equal(t, map[string]string{" file created ": " 2021-10-08T12:34:18+10:00 "}, m) m = p.parseMetadataRow("file created: 2021-10-08T12:34:18\t\r\r\n") - require.Equal(t, m, map[string]string{"file created": " 2021-10-08T12:34:18\t"}) + require.Equal(t, map[string]string{"file created": " 2021-10-08T12:34:18\t"}, m) p = &Parser{ ColumnNames: []string{"a", "b"}, MetadataRows: 5, @@ -916,13 +916,13 @@ func TestParseMetadataRow(t *testing.T) { m = p.parseMetadataRow("# this is a not matching string") require.Nil(t, m) m = p.parseMetadataRow("# key1 : value1 \r\n") - require.Equal(t, m, map[string]string{"key1": "value1"}) + require.Equal(t, map[string]string{"key1": "value1"}, m) m = p.parseMetadataRow("key2=1234\n") - require.Equal(t, m, map[string]string{"key2": "1234"}) + require.Equal(t, map[string]string{"key2": "1234"}, m) m = p.parseMetadataRow(" file created : 2021-10-08T12:34:18+10:00 \r\n") - require.Equal(t, m, map[string]string{"file created": "2021-10-08T12:34:18+10:00"}) + require.Equal(t, map[string]string{"file created": "2021-10-08T12:34:18+10:00"}, m) m = p.parseMetadataRow("file created: '2021-10-08T12:34:18'\r\n") - require.Equal(t, m, map[string]string{"file created": "2021-10-08T12:34:18"}) + require.Equal(t, map[string]string{"file created": "2021-10-08T12:34:18"}, m) } func TestParseCSVFileWithMetadata(t *testing.T) { diff --git a/plugins/parsers/grok/parser_test.go b/plugins/parsers/grok/parser_test.go index 06bdf2bcc18cd..785ecca24e7f4 100644 --- a/plugins/parsers/grok/parser_test.go +++ b/plugins/parsers/grok/parser_test.go @@ -1089,7 +1089,7 @@ func TestDynamicMeasurementModifier(t *testing.T) { require.NoError(t, p.Compile()) m, err := p.ParseLine("4 5 hello") require.NoError(t, err) - require.Equal(t, m.Name(), "hello") + require.Equal(t, "hello", m.Name()) } func TestStaticMeasurementModifier(t *testing.T) { @@ -1114,7 +1114,7 @@ func TestTwoMeasurementModifier(t *testing.T) { require.NoError(t, p.Compile()) m, err := p.ParseLine("4 5 hello") require.NoError(t, err) - require.Equal(t, m.Name(), "4 5 hello") + require.Equal(t, "4 5 hello", m.Name()) } func TestMeasurementModifierNoName(t *testing.T) { @@ -1126,7 +1126,7 @@ func TestMeasurementModifierNoName(t *testing.T) { require.NoError(t, p.Compile()) m, err := p.ParseLine("4 5 hello") require.NoError(t, err) - require.Equal(t, m.Name(), "hello") + require.Equal(t, "hello", m.Name()) } func TestEmptyYearInTimestamp(t *testing.T) { diff --git a/plugins/parsers/json/parser_test.go b/plugins/parsers/json/parser_test.go index 5ea82fa2ac906..affd4d9e10823 100644 --- a/plugins/parsers/json/parser_test.go +++ b/plugins/parsers/json/parser_test.go @@ -672,7 +672,7 @@ func TestUseCaseJSONQuery(t *testing.T) { actual, err := parser.Parse([]byte(testString)) require.NoError(t, err) require.Len(t, actual, 3) - require.Equal(t, actual[0].Fields()["last"], "Murphy") + require.Equal(t, "Murphy", actual[0].Fields()["last"]) } func TestTimeParser(t *testing.T) { diff --git a/plugins/parsers/xpath/parser_test.go b/plugins/parsers/xpath/parser_test.go index e8ba234ae3a39..a8359cad4b030 100644 --- a/plugins/parsers/xpath/parser_test.go +++ b/plugins/parsers/xpath/parser_test.go @@ -1184,7 +1184,7 @@ func TestEmptySelection(t *testing.T) { _, err := parser.Parse([]byte(tt.input)) require.Error(t, err) - require.Equal(t, err.Error(), "cannot parse with empty selection node") + require.Equal(t, "cannot parse with empty selection node", err.Error()) }) } } diff --git a/plugins/processors/ifname/ttl_cache_test.go b/plugins/processors/ifname/ttl_cache_test.go index 5e6cae32e0d3f..6f16756d8d4cb 100644 --- a/plugins/processors/ifname/ttl_cache_test.go +++ b/plugins/processors/ifname/ttl_cache_test.go @@ -24,7 +24,7 @@ func TestTTLCacheExpire(t *testing.T) { _, ok, _ := c.Get("ones") require.False(t, ok) require.Empty(t, c.lru.m) - require.Equal(t, c.lru.l.Len(), 0) + require.Equal(t, 0, c.lru.l.Len()) } func TestTTLCache(t *testing.T) { diff --git a/plugins/serializers/graphite/graphite_test.go b/plugins/serializers/graphite/graphite_test.go index 3338eff61edbf..2882587ca2b22 100644 --- a/plugins/serializers/graphite/graphite_test.go +++ b/plugins/serializers/graphite/graphite_test.go @@ -209,7 +209,7 @@ func TestSerializeMetricHostWithMultipleTemplatesWithDefault(t *testing.T) { }, } require.NoError(t, s.Init()) - require.Equal(t, s.Template, "tags.host.measurement.field") + require.Equal(t, "tags.host.measurement.field", s.Template) buf, err := s.Serialize(m1) require.NoError(t, err) diff --git a/plugins/serializers/msgpack/metric_test.go b/plugins/serializers/msgpack/metric_test.go index e85fe4a020feb..db084470434cd 100644 --- a/plugins/serializers/msgpack/metric_test.go +++ b/plugins/serializers/msgpack/metric_test.go @@ -15,7 +15,7 @@ func TestMsgPackTime32(t *testing.T) { var nsec int64 t1 := MessagePackTime{time: time.Unix(sec, nsec)} - require.Equal(t, t1.Len(), 4) + require.Equal(t, 4, t1.Len()) buf := make([]byte, t1.Len()) require.NoError(t, t1.MarshalBinaryTo(buf)) @@ -33,7 +33,7 @@ func TestMsgPackTime64(t *testing.T) { var nsec int64 = 999999999 t1 := MessagePackTime{time: time.Unix(sec, nsec)} - require.Equal(t, t1.Len(), 8) + require.Equal(t, 8, t1.Len()) buf := make([]byte, t1.Len()) require.NoError(t, t1.MarshalBinaryTo(buf)) @@ -51,7 +51,7 @@ func TestMsgPackTime96(t *testing.T) { var nsec int64 = 111111111 t1 := MessagePackTime{time: time.Unix(sec, nsec)} - require.Equal(t, t1.Len(), 12) + require.Equal(t, 12, t1.Len()) buf := make([]byte, t1.Len()) require.NoError(t, t1.MarshalBinaryTo(buf)) @@ -65,7 +65,7 @@ func TestMsgPackTime96(t *testing.T) { // Testing the default value: 0001-01-01T00:00:00Z t1 = MessagePackTime{} - require.Equal(t, t1.Len(), 12) + require.Equal(t, 12, t1.Len()) require.NoError(t, t1.MarshalBinaryTo(buf)) t2 = new(MessagePackTime) diff --git a/plugins/serializers/template/template_test.go b/plugins/serializers/template/template_test.go index 5fea65d3c3a5f..1ee3bd6b655b7 100644 --- a/plugins/serializers/template/template_test.go +++ b/plugins/serializers/template/template_test.go @@ -170,13 +170,12 @@ func TestSerializeBatch(t *testing.T) { require.NoError(t, err) require.Equal( t, - string(buf), `0: cpu 42 1: cpu 42 -`, +`, string(buf), ) // A batch template should still work when serializing a single metric singleBuf, err := s.Serialize(m) require.NoError(t, err) - require.Equal(t, string(singleBuf), "0: cpu 42\n") + require.Equal(t, "0: cpu 42\n", string(singleBuf)) }