Skip to content

Commit

Permalink
test(linters): Enable testifylint: blank-import, `encoded-compare…
Browse files Browse the repository at this point in the history
…` and `regexp`
  • Loading branch information
zak-pawel committed Dec 6, 2024
1 parent 304ab2e commit 9fd35bb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@ linters-settings:
- blank-import
- bool-compare
- compares
- contains
- empty
- encoded-compare
- error-is-as
- error-nil
- expected-actual
Expand All @@ -345,6 +347,7 @@ linters-settings:
- len
- negative-positive
- nil-compare
- regexp
- require-error
- suite-broken-parallel
- suite-dont-use-pkg
Expand Down
10 changes: 5 additions & 5 deletions plugins/serializers/json/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ func TestSerializeBatch(t *testing.T) {
require.NoError(t, s.Init())
buf, err := s.SerializeBatch(metrics)
require.NoError(t, err)
require.Equal(
require.JSONEq(
t,
[]byte(`{"metrics":[{"fields":{"value":42},"name":"cpu","tags":{},"timestamp":0},{"fields":{"value":42},"name":"cpu","tags":{},"timestamp":0}]}`+"\n"),
buf,
`{"metrics":[{"fields":{"value":42},"name":"cpu","tags":{},"timestamp":0},{"fields":{"value":42},"name":"cpu","tags":{},"timestamp":0}]}`,
string(buf),
)
}

Expand All @@ -220,7 +220,7 @@ func TestSerializeBatchSkipInf(t *testing.T) {
require.NoError(t, s.Init())
buf, err := s.SerializeBatch(metrics)
require.NoError(t, err)
require.Equal(t, []byte(`{"metrics":[{"fields":{"time_idle":42},"name":"cpu","tags":{},"timestamp":0}]}`+"\n"), buf)
require.JSONEq(t, `{"metrics":[{"fields":{"time_idle":42},"name":"cpu","tags":{},"timestamp":0}]}`, string(buf))
}

func TestSerializeBatchSkipInfAllFields(t *testing.T) {
Expand All @@ -239,7 +239,7 @@ func TestSerializeBatchSkipInfAllFields(t *testing.T) {
require.NoError(t, s.Init())
buf, err := s.SerializeBatch(metrics)
require.NoError(t, err)
require.Equal(t, []byte(`{"metrics":[{"fields":{},"name":"cpu","tags":{},"timestamp":0}]}`+"\n"), buf)
require.JSONEq(t, `{"metrics":[{"fields":{},"name":"cpu","tags":{},"timestamp":0}]}`, string(buf))
}

func TestSerializeTransformationNonBatch(t *testing.T) {
Expand Down
30 changes: 13 additions & 17 deletions plugins/serializers/nowmetric/nowmetric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,11 @@ func TestSerializeBatch(t *testing.T) {
s := &Serializer{}
buf, err := s.SerializeBatch(metrics)
require.NoError(t, err)
require.Equal(
require.JSONEq(
t,
[]byte(
`[{"metric_type":"value","resource":"","node":"","value":42,"timestamp":0,"ci2metric_id":null,"source":"Telegraf"},`+
`{"metric_type":"value","resource":"","node":"","value":42,"timestamp":0,"ci2metric_id":null,"source":"Telegraf"}]`,
),
buf,
`[{"metric_type":"value","resource":"","node":"","value":42,"timestamp":0,"ci2metric_id":null,"source":"Telegraf"},`+
`{"metric_type":"value","resource":"","node":"","value":42,"timestamp":0,"ci2metric_id":null,"source":"Telegraf"}]`,
string(buf),
)
}

Expand All @@ -213,10 +211,10 @@ func TestSerializeJSONv2Format(t *testing.T) {
s := &Serializer{Format: "jsonv2"}
buf, err := s.Serialize(m)
require.NoError(t, err)
require.Equal(
require.JSONEq(
t,
[]byte(`{"records":[{"metric_type":"value","resource":"","node":"","value":42,"timestamp":0,"ci2metric_id":null,"source":"Telegraf"}]}`),
buf,
`{"records":[{"metric_type":"value","resource":"","node":"","value":42,"timestamp":0,"ci2metric_id":null,"source":"Telegraf"}]}`,
string(buf),
)
}

Expand All @@ -233,15 +231,13 @@ func TestSerializeJSONv2FormatBatch(t *testing.T) {
metrics := []telegraf.Metric{m, m}
buf, err := s.SerializeBatch(metrics)
require.NoError(t, err)
require.Equal(
require.JSONEq(
t,
[]byte(
`{"records":[`+
`{"metric_type":"value","resource":"","node":"","value":42,"timestamp":0,"ci2metric_id":null,"source":"Telegraf"},`+
`{"metric_type":"value","resource":"","node":"","value":42,"timestamp":0,"ci2metric_id":null,"source":"Telegraf"}`+
`]}`,
),
buf,
`{"records":[`+
`{"metric_type":"value","resource":"","node":"","value":42,"timestamp":0,"ci2metric_id":null,"source":"Telegraf"},`+
`{"metric_type":"value","resource":"","node":"","value":42,"timestamp":0,"ci2metric_id":null,"source":"Telegraf"}`+
`]}`,
string(buf),
)
}

Expand Down

0 comments on commit 9fd35bb

Please sign in to comment.