From 62c39d6ba132ed5377620a53eebe6a265b5f5f3d Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Mon, 29 May 2023 17:38:43 -0700 Subject: [PATCH] [chore] lint issues: redefined built-in funcs (#22915) Linked to: #20424 Signed-off-by: Alex Boten --- .../storage/storagetest/extension_test.go | 4 +- internal/aws/cwlogs/pusher_test.go | 6 +-- internal/aws/proxy/server_test.go | 4 +- pkg/stanza/entry/copy_test.go | 33 +++++-------- pkg/stanza/entry/entry_test.go | 48 +++++++++---------- pkg/stanza/fileconsumer/file_test.go | 4 +- pkg/stanza/fileconsumer/fingerprint_test.go | 8 ++-- pkg/stanza/operator/input/file/file_test.go | 4 +- pkg/stanza/operator/parser/regex/cache.go | 6 +-- .../operator/transformer/copy/copy_test.go | 6 +-- .../mock_log_consumer_test.go | 6 +-- receiver/simpleprometheusreceiver/factory.go | 2 +- receiver/simpleprometheusreceiver/receiver.go | 4 +- receiver/snowflakereceiver/client.go | 3 +- 14 files changed, 63 insertions(+), 75 deletions(-) diff --git a/extension/storage/storagetest/extension_test.go b/extension/storage/storagetest/extension_test.go index c279df4ddc28..c2c445f21ef6 100644 --- a/extension/storage/storagetest/extension_test.go +++ b/extension/storage/storagetest/extension_test.go @@ -84,9 +84,9 @@ func runExtensionLifecycle(t *testing.T, ext *TestStorage, expectPersistence boo // Perform some additional operations set := storage.SetOperation("foo3", []byte("bar3")) get := storage.GetOperation("foo3") - delete := storage.DeleteOperation("foo3") + deleteOp := storage.DeleteOperation("foo3") getNil := storage.GetOperation("foo3") - require.NoError(t, clientTwo.Batch(ctx, set, get, delete, getNil)) + require.NoError(t, clientTwo.Batch(ctx, set, get, deleteOp, getNil)) require.Equal(t, get.Value, []byte("bar3")) require.Nil(t, getNil.Value) diff --git a/internal/aws/cwlogs/pusher_test.go b/internal/aws/cwlogs/pusher_test.go index dce23cd9f52f..c82ecf4a0009 100644 --- a/internal/aws/cwlogs/pusher_test.go +++ b/internal/aws/cwlogs/pusher_test.go @@ -198,14 +198,14 @@ func TestPusher_newLogEventBatch(t *testing.T) { func TestPusher_addLogEventBatch(t *testing.T) { p := newMockPusher() - cap := cap(p.logEventBatch.putLogEventsInput.LogEvents) + c := cap(p.logEventBatch.putLogEventsInput.LogEvents) logEvent := NewEvent(timestampMs, msg) - for i := 0; i < cap; i++ { + for i := 0; i < c; i++ { p.logEventBatch.putLogEventsInput.LogEvents = append(p.logEventBatch.putLogEventsInput.LogEvents, logEvent.InputLogEvent) } - assert.Equal(t, cap, len(p.logEventBatch.putLogEventsInput.LogEvents)) + assert.Equal(t, c, len(p.logEventBatch.putLogEventsInput.LogEvents)) assert.NotNil(t, p.addLogEvent(logEvent)) // the actual log event add operation happens after the func newLogEventBatchIfNeeded diff --git a/internal/aws/proxy/server_test.go b/internal/aws/proxy/server_test.go index 4601d2801870..2a7d10afcba6 100644 --- a/internal/aws/proxy/server_test.go +++ b/internal/aws/proxy/server_test.go @@ -184,9 +184,9 @@ func TestCantGetAWSConfigSession(t *testing.T) { tcpAddr := testutil.GetAvailableLocalAddress(t) cfg.TCPAddr.Endpoint = tcpAddr - real := newAWSSession + origSession := newAWSSession defer func() { - newAWSSession = real + newAWSSession = origSession }() expectedErr := errors.New("expected newAWSSessionError") diff --git a/pkg/stanza/entry/copy_test.go b/pkg/stanza/entry/copy_test.go index b867e049d406..65bb903f2ba4 100644 --- a/pkg/stanza/entry/copy_test.go +++ b/pkg/stanza/entry/copy_test.go @@ -11,68 +11,57 @@ import ( func TestCopyValueString(t *testing.T) { value := "test" - copy := copyValue(value) - require.Equal(t, "test", copy) + require.Equal(t, "test", copyValue(value)) } func TestCopyValueBool(t *testing.T) { value := true - copy := copyValue(value) - require.Equal(t, true, copy) + require.Equal(t, true, copyValue(value)) } func TestCopyValueInt(t *testing.T) { value := 5 - copy := copyValue(value) - require.Equal(t, 5, copy) + require.Equal(t, 5, copyValue(value)) } func TestCopyValueByte(t *testing.T) { value := []byte("test")[0] - copy := copyValue(value) - require.Equal(t, []byte("test")[0], copy) + require.Equal(t, []byte("test")[0], copyValue(value)) } func TestCopyValueNil(t *testing.T) { var value interface{} - copy := copyValue(value) - require.Equal(t, nil, copy) + require.Equal(t, nil, copyValue(value)) } func TestCopyValueStringArray(t *testing.T) { value := []string{"test"} - copy := copyValue(value) - require.Equal(t, value, copy) + require.Equal(t, value, copyValue(value)) } func TestCopyValueIntArray(t *testing.T) { value := []int{5} - copy := copyValue(value) - require.Equal(t, value, copy) + require.Equal(t, value, copyValue(value)) } func TestCopyValueByteArray(t *testing.T) { value := []byte("x") - copy := copyValue(value) - require.Equal(t, value, copy) + require.Equal(t, value, copyValue(value)) } func TestCopyValueInterfaceArray(t *testing.T) { value := []interface{}{"test", true, 5} - copy := copyValue(value) - require.Equal(t, value, copy) + require.Equal(t, value, copyValue(value)) } func TestCopyValueStringMap(t *testing.T) { value := map[string]string{"test": "value"} - copy := copyValue(value) - require.Equal(t, value, copy) + require.Equal(t, value, copyValue(value)) } func TestCopyValueInterfaceMap(t *testing.T) { value := map[string]interface{}{"test": 5} - copy := copyValue(value) - require.Equal(t, value, copy) + require.Equal(t, value, copyValue(value)) } func TestCopyValueUnknown(t *testing.T) { diff --git a/pkg/stanza/entry/entry_test.go b/pkg/stanza/entry/entry_test.go index a83be090c869..07f852a029ec 100644 --- a/pkg/stanza/entry/entry_test.go +++ b/pkg/stanza/entry/entry_test.go @@ -136,7 +136,7 @@ func TestCopy(t *testing.T) { entry.SpanID = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08} entry.TraceFlags = []byte{0x01} entry.ScopeName = "my.logger" - copy := entry.Copy() + cp := entry.Copy() entry.Severity = Severity(1) entry.SeverityText = "1" @@ -149,24 +149,24 @@ func TestCopy(t *testing.T) { entry.TraceFlags[0] = 0xff entry.ScopeName = "foo" - require.Equal(t, now, copy.ObservedTimestamp) - require.Equal(t, time.Time{}, copy.Timestamp) - require.Equal(t, Severity(0), copy.Severity) - require.Equal(t, "ok", copy.SeverityText) - require.Equal(t, map[string]interface{}{"label": "value"}, copy.Attributes) - require.Equal(t, map[string]interface{}{"resource": "value"}, copy.Resource) - require.Equal(t, "test", copy.Body) - require.Equal(t, []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, copy.TraceID) - require.Equal(t, []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, copy.SpanID) - require.Equal(t, []byte{0x01}, copy.TraceFlags) - require.Equal(t, "my.logger", copy.ScopeName) + require.Equal(t, now, cp.ObservedTimestamp) + require.Equal(t, time.Time{}, cp.Timestamp) + require.Equal(t, Severity(0), cp.Severity) + require.Equal(t, "ok", cp.SeverityText) + require.Equal(t, map[string]interface{}{"label": "value"}, cp.Attributes) + require.Equal(t, map[string]interface{}{"resource": "value"}, cp.Resource) + require.Equal(t, "test", cp.Body) + require.Equal(t, []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, cp.TraceID) + require.Equal(t, []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, cp.SpanID) + require.Equal(t, []byte{0x01}, cp.TraceFlags) + require.Equal(t, "my.logger", cp.ScopeName) } func TestCopyNil(t *testing.T) { now := time.Now() entry := New() entry.ObservedTimestamp = now - copy := entry.Copy() + cp := entry.Copy() entry.Severity = Severity(1) entry.SeverityText = "1" @@ -179,17 +179,17 @@ func TestCopyNil(t *testing.T) { entry.TraceFlags = []byte{0x01} entry.ScopeName = "foo" - require.Equal(t, now, copy.ObservedTimestamp) - require.Equal(t, time.Time{}, copy.Timestamp) - require.Equal(t, Severity(0), copy.Severity) - require.Equal(t, "", copy.SeverityText) - require.Equal(t, map[string]interface{}{}, copy.Attributes) - require.Equal(t, map[string]interface{}{}, copy.Resource) - require.Equal(t, nil, copy.Body) - require.Equal(t, []byte{}, copy.TraceID) - require.Equal(t, []byte{}, copy.SpanID) - require.Equal(t, []byte{}, copy.TraceFlags) - require.Equal(t, "", copy.ScopeName) + require.Equal(t, now, cp.ObservedTimestamp) + require.Equal(t, time.Time{}, cp.Timestamp) + require.Equal(t, Severity(0), cp.Severity) + require.Equal(t, "", cp.SeverityText) + require.Equal(t, map[string]interface{}{}, cp.Attributes) + require.Equal(t, map[string]interface{}{}, cp.Resource) + require.Equal(t, nil, cp.Body) + require.Equal(t, []byte{}, cp.TraceID) + require.Equal(t, []byte{}, cp.SpanID) + require.Equal(t, []byte{}, cp.TraceFlags) + require.Equal(t, "", cp.ScopeName) } func TestFieldFromString(t *testing.T) { diff --git a/pkg/stanza/fileconsumer/file_test.go b/pkg/stanza/fileconsumer/file_test.go index ce3a78174160..f517a53f1dc9 100644 --- a/pkg/stanza/fileconsumer/file_test.go +++ b/pkg/stanza/fileconsumer/file_test.go @@ -104,9 +104,9 @@ func TestAddFileResolvedFields(t *testing.T) { writeString(t, file, "testlog\n") // Resolve path - real, err := filepath.EvalSymlinks(file.Name()) + realPath, err := filepath.EvalSymlinks(file.Name()) require.NoError(t, err) - resolved, err := filepath.Abs(real) + resolved, err := filepath.Abs(realPath) require.NoError(t, err) require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) diff --git a/pkg/stanza/fileconsumer/fingerprint_test.go b/pkg/stanza/fileconsumer/fingerprint_test.go index 84685bb567aa..87b0a9098d2f 100644 --- a/pkg/stanza/fileconsumer/fingerprint_test.go +++ b/pkg/stanza/fileconsumer/fingerprint_test.go @@ -154,22 +154,22 @@ func TestFingerprintCopy(t *testing.T) { for _, tc := range cases { fp := &Fingerprint{FirstBytes: []byte(tc)} - copy := fp.Copy() + cp := fp.Copy() // Did not change original require.Equal(t, tc, string(fp.FirstBytes)) // Copy is also good - require.Equal(t, tc, string(copy.FirstBytes)) + require.Equal(t, tc, string(cp.FirstBytes)) // Modify copy - copy.FirstBytes = append(copy.FirstBytes, []byte("also")...) + cp.FirstBytes = append(cp.FirstBytes, []byte("also")...) // Still did not change original require.Equal(t, tc, string(fp.FirstBytes)) // Copy is modified - require.Equal(t, tc+"also", string(copy.FirstBytes)) + require.Equal(t, tc+"also", string(cp.FirstBytes)) } } diff --git a/pkg/stanza/operator/input/file/file_test.go b/pkg/stanza/operator/input/file/file_test.go index ba37fb0bb54c..8fced8146474 100644 --- a/pkg/stanza/operator/input/file/file_test.go +++ b/pkg/stanza/operator/input/file/file_test.go @@ -48,9 +48,9 @@ func TestAddFileResolvedFields(t *testing.T) { writeString(t, file, "testlog\n") // Resolve path - real, err := filepath.EvalSymlinks(file.Name()) + realPath, err := filepath.EvalSymlinks(file.Name()) require.NoError(t, err) - resolved, err := filepath.Abs(real) + resolved, err := filepath.Abs(realPath) require.NoError(t, err) require.NoError(t, operator.Start(testutil.NewMockPersister("test"))) diff --git a/pkg/stanza/operator/parser/regex/cache.go b/pkg/stanza/operator/parser/regex/cache.go index 74736e4ec782..3f69cb8cd69c 100644 --- a/pkg/stanza/operator/parser/regex/cache.go +++ b/pkg/stanza/operator/parser/regex/cache.go @@ -95,15 +95,15 @@ func (m *memoryCache) add(key string, data interface{}) bool { // copy returns a deep copy of the cache func (m *memoryCache) copy() map[string]interface{} { - copy := make(map[string]interface{}, cap(m.keys)) + cp := make(map[string]interface{}, cap(m.keys)) m.mutex.Lock() defer m.mutex.Unlock() for k, v := range m.cache { - copy[k] = v + cp[k] = v } - return copy + return cp } // maxSize returns the max size of the cache diff --git a/pkg/stanza/operator/transformer/copy/copy_test.go b/pkg/stanza/operator/transformer/copy/copy_test.go index d250e51ec39f..f408a7c63022 100644 --- a/pkg/stanza/operator/transformer/copy/copy_test.go +++ b/pkg/stanza/operator/transformer/copy/copy_test.go @@ -290,11 +290,11 @@ func TestBuildAndProcess(t *testing.T) { op, err := cfg.Build(testutil.Logger(t)) require.NoError(t, err) - copy := op.(*Transformer) + cp := op.(*Transformer) fake := testutil.NewFakeOutput(t) - require.NoError(t, copy.SetOutputs([]operator.Operator{fake})) + require.NoError(t, cp.SetOutputs([]operator.Operator{fake})) val := tc.input() - err = copy.Process(context.Background(), val) + err = cp.Process(context.Background(), val) if tc.expectErr { require.Error(t, err) } else { diff --git a/receiver/k8sobjectsreceiver/mock_log_consumer_test.go b/receiver/k8sobjectsreceiver/mock_log_consumer_test.go index 3b72ea8733d4..20e70b50558c 100644 --- a/receiver/k8sobjectsreceiver/mock_log_consumer_test.go +++ b/receiver/k8sobjectsreceiver/mock_log_consumer_test.go @@ -49,9 +49,9 @@ func (m *mockLogConsumer) Logs() []plog.Logs { defer m.lock.Unlock() logs := make([]plog.Logs, len(m.logs)) for i, log := range m.logs { - copy := plog.NewLogs() - log.CopyTo(copy) - logs[i] = copy + l := plog.NewLogs() + log.CopyTo(l) + logs[i] = l } return logs diff --git a/receiver/simpleprometheusreceiver/factory.go b/receiver/simpleprometheusreceiver/factory.go index 4f5188813cf8..6300ef8eb62e 100644 --- a/receiver/simpleprometheusreceiver/factory.go +++ b/receiver/simpleprometheusreceiver/factory.go @@ -52,5 +52,5 @@ func createMetricsReceiver( nextConsumer consumer.Metrics, ) (receiver.Metrics, error) { rCfg := cfg.(*Config) - return new(params, rCfg, nextConsumer), nil + return newPrometheusReceiverWrapper(params, rCfg, nextConsumer), nil } diff --git a/receiver/simpleprometheusreceiver/receiver.go b/receiver/simpleprometheusreceiver/receiver.go index 05b502bc172e..1e6f483fd9b7 100644 --- a/receiver/simpleprometheusreceiver/receiver.go +++ b/receiver/simpleprometheusreceiver/receiver.go @@ -29,8 +29,8 @@ type prometheusReceiverWrapper struct { prometheusRecever receiver.Metrics } -// new returns a prometheusReceiverWrapper -func new(params receiver.CreateSettings, cfg *Config, consumer consumer.Metrics) *prometheusReceiverWrapper { +// newPrometheusReceiverWrapper returns a prometheusReceiverWrapper +func newPrometheusReceiverWrapper(params receiver.CreateSettings, cfg *Config, consumer consumer.Metrics) *prometheusReceiverWrapper { return &prometheusReceiverWrapper{params: params, config: cfg, consumer: consumer} } diff --git a/receiver/snowflakereceiver/client.go b/receiver/snowflakereceiver/client.go index 7ebbeaaf1f3c..50faa7a53679 100644 --- a/receiver/snowflakereceiver/client.go +++ b/receiver/snowflakereceiver/client.go @@ -72,8 +72,7 @@ func newDefaultClient(settings component.TelemetrySettings, c Config) (*snowflak func (c snowflakeClient) readDB(ctx context.Context, q string) (*sql.Rows, error) { rows, err := c.client.QueryContext(ctx, q) if err != nil { - error := fmt.Sprintf("Query failed with %v", err) - c.logger.Error(error) + c.logger.Error(fmt.Sprintf("Query failed with %v", err)) return nil, err }