Skip to content

Commit

Permalink
fix: Linter fixes for plugins/inputs/[a-o]* (leftovers) (influxdata#1…
Browse files Browse the repository at this point in the history
…0192)

Co-authored-by: Pawel Zak <Pawel Zak>
  • Loading branch information
zak-pawel authored Nov 30, 2021
1 parent 3627961 commit c875e45
Show file tree
Hide file tree
Showing 24 changed files with 221 additions and 228 deletions.
23 changes: 12 additions & 11 deletions plugins/inputs/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/assert"
)

func TestBindJsonStats(t *testing.T) {
Expand All @@ -29,7 +30,7 @@ func TestBindJsonStats(t *testing.T) {
var acc testutil.Accumulator
err := acc.GatherError(b.Gather)

assert.NoError(t, err)
require.NoError(t, err)

// Use subtests for counters, since they are similar structure
type fieldSet struct {
Expand Down Expand Up @@ -179,8 +180,8 @@ func TestBindJsonStats(t *testing.T) {

// Subtest for per-context memory stats
t.Run("memory_context", func(t *testing.T) {
assert.True(t, acc.HasInt64Field("bind_memory_context", "total"))
assert.True(t, acc.HasInt64Field("bind_memory_context", "in_use"))
require.True(t, acc.HasInt64Field("bind_memory_context", "total"))
require.True(t, acc.HasInt64Field("bind_memory_context", "in_use"))
})
}

Expand All @@ -202,7 +203,7 @@ func TestBindXmlStatsV2(t *testing.T) {
var acc testutil.Accumulator
err := acc.GatherError(b.Gather)

assert.NoError(t, err)
require.NoError(t, err)

// Use subtests for counters, since they are similar structure
type fieldSet struct {
Expand Down Expand Up @@ -384,8 +385,8 @@ func TestBindXmlStatsV2(t *testing.T) {

// Subtest for per-context memory stats
t.Run("memory_context", func(t *testing.T) {
assert.True(t, acc.HasInt64Field("bind_memory_context", "total"))
assert.True(t, acc.HasInt64Field("bind_memory_context", "in_use"))
require.True(t, acc.HasInt64Field("bind_memory_context", "total"))
require.True(t, acc.HasInt64Field("bind_memory_context", "in_use"))
})
}

Expand All @@ -407,7 +408,7 @@ func TestBindXmlStatsV3(t *testing.T) {
var acc testutil.Accumulator
err := acc.GatherError(b.Gather)

assert.NoError(t, err)
require.NoError(t, err)

// Use subtests for counters, since they are similar structure
type fieldSet struct {
Expand Down Expand Up @@ -611,8 +612,8 @@ func TestBindXmlStatsV3(t *testing.T) {

// Subtest for per-context memory stats
t.Run("memory_context", func(t *testing.T) {
assert.True(t, acc.HasInt64Field("bind_memory_context", "total"))
assert.True(t, acc.HasInt64Field("bind_memory_context", "in_use"))
require.True(t, acc.HasInt64Field("bind_memory_context", "total"))
require.True(t, acc.HasInt64Field("bind_memory_context", "in_use"))
})
}

Expand All @@ -623,5 +624,5 @@ func TestBindUnparseableURL(t *testing.T) {

var acc testutil.Accumulator
err := acc.GatherError(b.Gather)
assert.Contains(t, err.Error(), "unable to parse address")
require.Contains(t, err.Error(), "unable to parse address")
}
27 changes: 13 additions & 14 deletions plugins/inputs/cassandra/cassandra_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package cassandra

import (
_ "fmt"
"io"
"net/http"
"strings"
"testing"

"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/assert"
_ "github.com/stretchr/testify/require"
)

const validJavaMultiValueJSON = `
Expand Down Expand Up @@ -138,8 +137,8 @@ func TestHttpJsonJavaMultiValue(t *testing.T) {
acc.SetDebug(true)
err := acc.GatherError(cassandra.Gather)

assert.NoError(t, err)
assert.Equal(t, 2, len(acc.Metrics))
require.NoError(t, err)
require.Equal(t, 2, len(acc.Metrics))

fields := map[string]interface{}{
"HeapMemoryUsage_init": 67108864.0,
Expand Down Expand Up @@ -167,8 +166,8 @@ func TestHttpJsonJavaMultiType(t *testing.T) {
acc.SetDebug(true)
err := acc.GatherError(cassandra.Gather)

assert.NoError(t, err)
assert.Equal(t, 2, len(acc.Metrics))
require.NoError(t, err)
require.Equal(t, 2, len(acc.Metrics))

fields := map[string]interface{}{
"CollectionCount": 1.0,
Expand All @@ -188,9 +187,9 @@ func TestHttp404(t *testing.T) {
var acc testutil.Accumulator
err := acc.GatherError(jolokia.Gather)

assert.Error(t, err)
assert.Equal(t, 0, len(acc.Metrics))
assert.Contains(t, err.Error(), "has status code 404")
require.Error(t, err)
require.Equal(t, 0, len(acc.Metrics))
require.Contains(t, err.Error(), "has status code 404")
}

// Test that the proper values are ignored or collected for class=Cassandra
Expand All @@ -200,8 +199,8 @@ func TestHttpJsonCassandraMultiValue(t *testing.T) {
var acc testutil.Accumulator
err := acc.GatherError(cassandra.Gather)

assert.NoError(t, err)
assert.Equal(t, 1, len(acc.Metrics))
require.NoError(t, err)
require.Equal(t, 1, len(acc.Metrics))

fields := map[string]interface{}{
"ReadLatency_999thPercentile": 20.0,
Expand Down Expand Up @@ -232,8 +231,8 @@ func TestHttpJsonCassandraNestedMultiValue(t *testing.T) {
acc.SetDebug(true)
err := acc.GatherError(cassandra.Gather)

assert.NoError(t, err)
assert.Equal(t, 2, len(acc.Metrics))
require.NoError(t, err)
require.Equal(t, 2, len(acc.Metrics))

fields1 := map[string]interface{}{
"ReadLatency_999thPercentile": 1.0,
Expand Down
21 changes: 11 additions & 10 deletions plugins/inputs/cloud_pubsub/pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"errors"
"testing"

"github.com/stretchr/testify/require"

"github.com/influxdata/telegraf/plugins/parsers"
"github.com/influxdata/telegraf/testutil"
"github.com/stretchr/testify/assert"
)

const (
Expand Down Expand Up @@ -53,7 +54,7 @@ func TestRunParse(t *testing.T) {
sub.messages <- msg

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

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

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

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

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

func TestRunErrorInSubscriber(t *testing.T) {
Expand Down Expand Up @@ -228,12 +229,12 @@ func TestRunErrorInSubscriber(t *testing.T) {
t.Fatal("expected plugin subscription to be non-nil")
}
acc.WaitError(1)
assert.Regexp(t, fakeErrStr, acc.Errors[0])
require.Regexp(t, fakeErrStr, acc.Errors[0])
}

func validateTestInfluxMetric(t *testing.T, m *testutil.Metric) {
assert.Equal(t, "cpu_load_short", m.Measurement)
assert.Equal(t, "server01", m.Tags["host"])
assert.Equal(t, 23422.0, m.Fields["value"])
assert.Equal(t, int64(1422568543702900257), m.Time.UnixNano())
require.Equal(t, "cpu_load_short", m.Measurement)
require.Equal(t, "server01", m.Tags["host"])
require.Equal(t, 23422.0, m.Fields["value"])
require.Equal(t, int64(1422568543702900257), m.Time.UnixNano())
}
27 changes: 14 additions & 13 deletions plugins/inputs/csgo/csgo_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package csgo

import (
"github.com/influxdata/telegraf/testutil"
"testing"

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

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

const testInput = `CPU NetIn NetOut Uptime Maps FPS Players Svms +-ms ~tick
Expand All @@ -28,17 +29,17 @@ func TestCPUStats(t *testing.T) {
t.Errorf("acc.HasMeasurement: expected csgo")
}

assert.Equal(t, "1.2.3.4:1234", acc.Metrics[0].Tags["host"])
assert.Equal(t, expectedOutput.CPU, acc.Metrics[0].Fields["cpu"])
assert.Equal(t, expectedOutput.NetIn, acc.Metrics[0].Fields["net_in"])
assert.Equal(t, expectedOutput.NetOut, acc.Metrics[0].Fields["net_out"])
assert.Equal(t, expectedOutput.UptimeMinutes, acc.Metrics[0].Fields["uptime_minutes"])
assert.Equal(t, expectedOutput.Maps, acc.Metrics[0].Fields["maps"])
assert.Equal(t, expectedOutput.FPS, acc.Metrics[0].Fields["fps"])
assert.Equal(t, expectedOutput.Players, acc.Metrics[0].Fields["players"])
assert.Equal(t, expectedOutput.Sim, acc.Metrics[0].Fields["sv_ms"])
assert.Equal(t, expectedOutput.Variance, acc.Metrics[0].Fields["variance_ms"])
assert.Equal(t, expectedOutput.Tick, acc.Metrics[0].Fields["tick_ms"])
require.Equal(t, "1.2.3.4:1234", acc.Metrics[0].Tags["host"])
require.Equal(t, expectedOutput.CPU, acc.Metrics[0].Fields["cpu"])
require.Equal(t, expectedOutput.NetIn, acc.Metrics[0].Fields["net_in"])
require.Equal(t, expectedOutput.NetOut, acc.Metrics[0].Fields["net_out"])
require.Equal(t, expectedOutput.UptimeMinutes, acc.Metrics[0].Fields["uptime_minutes"])
require.Equal(t, expectedOutput.Maps, acc.Metrics[0].Fields["maps"])
require.Equal(t, expectedOutput.FPS, acc.Metrics[0].Fields["fps"])
require.Equal(t, expectedOutput.Players, acc.Metrics[0].Fields["players"])
require.Equal(t, expectedOutput.Sim, acc.Metrics[0].Fields["sv_ms"])
require.Equal(t, expectedOutput.Variance, acc.Metrics[0].Fields["variance_ms"])
require.Equal(t, expectedOutput.Tick, acc.Metrics[0].Fields["tick_ms"])
}

func requestMock(_ string, _ string) (string, error) {
Expand Down
8 changes: 4 additions & 4 deletions plugins/inputs/dcos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"net/url"
"time"

jwt "github.com/golang-jwt/jwt/v4"
"github.com/golang-jwt/jwt/v4"
)

const (
Expand Down Expand Up @@ -100,7 +100,7 @@ type ClusterClient struct {

type claims struct {
UID string `json:"uid"`
jwt.StandardClaims
jwt.RegisteredClaims
}

func (e APIError) Error() string {
Expand Down Expand Up @@ -327,9 +327,9 @@ func (c *ClusterClient) toURL(path string) string {
func (c *ClusterClient) createLoginToken(sa *ServiceAccount) (string, error) {
token := jwt.NewWithClaims(jwt.SigningMethodRS256, claims{
UID: sa.AccountID,
StandardClaims: jwt.StandardClaims{
RegisteredClaims: jwt.RegisteredClaims{
// How long we have to login with this token
ExpiresAt: time.Now().Add(time.Minute * 5).Unix(),
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * 5)),
},
})
return token.SignedString(sa.PrivateKey)
Expand Down
6 changes: 2 additions & 4 deletions plugins/inputs/dcos/dcos.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"sync"
"time"

jwt "github.com/golang-jwt/jwt/v4"
"github.com/golang-jwt/jwt/v4"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/config"
Expand Down Expand Up @@ -237,9 +237,7 @@ func (d *DCOS) createPoints(m *Metrics) []*point {
fieldKey = fieldKey + "_bytes"
}

if strings.HasPrefix(fieldKey, "dcos_metrics_module_") {
fieldKey = strings.TrimPrefix(fieldKey, "dcos_metrics_module_")
}
fieldKey = strings.TrimPrefix(fieldKey, "dcos_metrics_module_")

tagset := make([]string, 0, len(tags))
for k, v := range tags {
Expand Down
Loading

0 comments on commit c875e45

Please sign in to comment.