Skip to content

Commit

Permalink
[chore] lint issues: redefined built-in funcs (#22915)
Browse files Browse the repository at this point in the history
Linked to: #20424

Signed-off-by: Alex Boten <[email protected]>
  • Loading branch information
Alex Boten authored May 30, 2023
1 parent f20113f commit 62c39d6
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 75 deletions.
4 changes: 2 additions & 2 deletions extension/storage/storagetest/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions internal/aws/cwlogs/pusher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/aws/proxy/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
33 changes: 11 additions & 22 deletions pkg/stanza/entry/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
48 changes: 24 additions & 24 deletions pkg/stanza/entry/entry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/stanza/fileconsumer/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down
8 changes: 4 additions & 4 deletions pkg/stanza/fileconsumer/fingerprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/stanza/operator/input/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down
6 changes: 3 additions & 3 deletions pkg/stanza/operator/parser/regex/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/stanza/operator/transformer/copy/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions receiver/k8sobjectsreceiver/mock_log_consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion receiver/simpleprometheusreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions receiver/simpleprometheusreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

Expand Down
3 changes: 1 addition & 2 deletions receiver/snowflakereceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 62c39d6

Please sign in to comment.