From f949b9d7cd92ebfba44d74c8aae5b53a5c42c489 Mon Sep 17 00:00:00 2001 From: Jacob Marble Date: Sun, 18 Jul 2021 18:00:57 -0700 Subject: [PATCH 1/4] pdata: add TypeSlice.Sort(func) to sort slices Comparing two generated slices can be tedious when the slices are not ordered, and order does not matter for the test. This change adds a .Sort(func(i, j int) bool) method to generated [Type]Slice. This is similar to method StringMap.Sort(), but takes a less function because the order may differ by context, where the sort order of a map is obvious (by key). --- cmd/pdatagen/internal/base_slices.go | 12 +++- cmd/pdatagen/internal/log_structs.go | 2 + cmd/pdatagen/internal/metrics_structs.go | 2 + cmd/pdatagen/internal/trace_structs.go | 2 + model/pdata/generated_common.go | 1 - model/pdata/generated_common_test.go | 5 +- model/pdata/generated_log.go | 29 +++++++++ model/pdata/generated_log_test.go | 15 +++-- model/pdata/generated_metrics.go | 78 +++++++++++++++++++++++- model/pdata/generated_metrics_test.go | 58 ++++++++++++------ model/pdata/generated_resource_test.go | 1 + model/pdata/generated_trace.go | 47 ++++++++++++++ model/pdata/generated_trace_test.go | 26 +++++--- 13 files changed, 236 insertions(+), 42 deletions(-) diff --git a/cmd/pdatagen/internal/base_slices.go b/cmd/pdatagen/internal/base_slices.go index 3f0dbb6b7ff..27316cb44e6 100644 --- a/cmd/pdatagen/internal/base_slices.go +++ b/cmd/pdatagen/internal/base_slices.go @@ -200,7 +200,17 @@ func (es ${structName}) EnsureCapacity(newCap int) { func (es ${structName}) AppendEmpty() ${elementName} { *es.orig = append(*es.orig, &${originName}{}) return es.At(es.Len() - 1) -} ` +} + +// Sort sorts the ${elementName} elements within ${structName} given the +// provided less function so that two instances can be compared. +// +// Returns the same instance to allow nicer code like: +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +func (es ${structName}) Sort(less func(i, j int) bool) ${structName} { + sort.SliceStable(*es.orig, less) + return es +}` const slicePtrTestTemplate = `func Test${structName}(t *testing.T) { es := New${structName}() diff --git a/cmd/pdatagen/internal/log_structs.go b/cmd/pdatagen/internal/log_structs.go index 3b29744c793..fcb442902e5 100644 --- a/cmd/pdatagen/internal/log_structs.go +++ b/cmd/pdatagen/internal/log_structs.go @@ -17,6 +17,8 @@ package internal var logFile = &File{ Name: "log", imports: []string{ + `"sort"`, + ``, `otlplogs "go.opentelemetry.io/collector/model/internal/data/protogen/logs/v1"`, }, testImports: []string{ diff --git a/cmd/pdatagen/internal/metrics_structs.go b/cmd/pdatagen/internal/metrics_structs.go index 463b78eb558..bf97296d993 100644 --- a/cmd/pdatagen/internal/metrics_structs.go +++ b/cmd/pdatagen/internal/metrics_structs.go @@ -17,6 +17,8 @@ package internal var metricsFile = &File{ Name: "metrics", imports: []string{ + `"sort"`, + ``, `otlpmetrics "go.opentelemetry.io/collector/model/internal/data/protogen/metrics/v1"`, }, testImports: []string{ diff --git a/cmd/pdatagen/internal/trace_structs.go b/cmd/pdatagen/internal/trace_structs.go index 5b3cbc3802e..dd6af4ca28b 100644 --- a/cmd/pdatagen/internal/trace_structs.go +++ b/cmd/pdatagen/internal/trace_structs.go @@ -17,6 +17,8 @@ package internal var traceFile = &File{ Name: "trace", imports: []string{ + `"sort"`, + ``, `otlptrace "go.opentelemetry.io/collector/model/internal/data/protogen/trace/v1"`, }, testImports: []string{ diff --git a/model/pdata/generated_common.go b/model/pdata/generated_common.go index faae97875e7..842554f2371 100644 --- a/model/pdata/generated_common.go +++ b/model/pdata/generated_common.go @@ -154,7 +154,6 @@ func (es AnyValueArray) AppendEmpty() AttributeValue { *es.orig = append(*es.orig, otlpcommon.AnyValue{}) return es.At(es.Len() - 1) } - // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es AnyValueArray) MoveAndAppendTo(dest AnyValueArray) { diff --git a/model/pdata/generated_common_test.go b/model/pdata/generated_common_test.go index 3ef9f668ada..e80280af875 100644 --- a/model/pdata/generated_common_test.go +++ b/model/pdata/generated_common_test.go @@ -25,6 +25,7 @@ import ( otlpcommon "go.opentelemetry.io/collector/model/internal/data/protogen/common/v1" ) + func TestInstrumentationLibrary_CopyTo(t *testing.T) { ms := NewInstrumentationLibrary() generateTestInstrumentationLibrary().CopyTo(ms) @@ -133,7 +134,7 @@ func TestAnyValueArray_MoveAndAppendTo(t *testing.T) { func TestAnyValueArray_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewAnyValueArray() - emptySlice.RemoveIf(func(el AttributeValue) bool { + emptySlice.RemoveIf(func (el AttributeValue) bool { t.Fail() return false }) @@ -141,7 +142,7 @@ func TestAnyValueArray_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestAnyValueArray() pos := 0 - filtered.RemoveIf(func(el AttributeValue) bool { + filtered.RemoveIf(func (el AttributeValue) bool { pos++ return pos%3 == 0 }) diff --git a/model/pdata/generated_log.go b/model/pdata/generated_log.go index 70878b50b5a..104e23d10fd 100644 --- a/model/pdata/generated_log.go +++ b/model/pdata/generated_log.go @@ -18,6 +18,8 @@ package pdata import ( + "sort" + otlplogs "go.opentelemetry.io/collector/model/internal/data/protogen/logs/v1" ) @@ -112,6 +114,15 @@ func (es ResourceLogsSlice) AppendEmpty() ResourceLogs { return es.At(es.Len() - 1) } +// Sort sorts the ResourceLogs elements within ResourceLogsSlice given the +// provided less function so that two instances can be compared. +// +// Returns the same instance to allow nicer code like: +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +func (es ResourceLogsSlice) Sort(less func(i, j int) bool) ResourceLogsSlice { + sort.SliceStable(*es.orig, less) + return es +} // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ResourceLogsSlice) MoveAndAppendTo(dest ResourceLogsSlice) { @@ -273,6 +284,15 @@ func (es InstrumentationLibraryLogsSlice) AppendEmpty() InstrumentationLibraryLo return es.At(es.Len() - 1) } +// Sort sorts the InstrumentationLibraryLogs elements within InstrumentationLibraryLogsSlice given the +// provided less function so that two instances can be compared. +// +// Returns the same instance to allow nicer code like: +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +func (es InstrumentationLibraryLogsSlice) Sort(less func(i, j int) bool) InstrumentationLibraryLogsSlice { + sort.SliceStable(*es.orig, less) + return es +} // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es InstrumentationLibraryLogsSlice) MoveAndAppendTo(dest InstrumentationLibraryLogsSlice) { @@ -434,6 +454,15 @@ func (es LogSlice) AppendEmpty() LogRecord { return es.At(es.Len() - 1) } +// Sort sorts the LogRecord elements within LogSlice given the +// provided less function so that two instances can be compared. +// +// Returns the same instance to allow nicer code like: +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +func (es LogSlice) Sort(less func(i, j int) bool) LogSlice { + sort.SliceStable(*es.orig, less) + return es +} // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es LogSlice) MoveAndAppendTo(dest LogSlice) { diff --git a/model/pdata/generated_log_test.go b/model/pdata/generated_log_test.go index 7b4c8a3e5d2..4819a205759 100644 --- a/model/pdata/generated_log_test.go +++ b/model/pdata/generated_log_test.go @@ -120,7 +120,7 @@ func TestResourceLogsSlice_MoveAndAppendTo(t *testing.T) { func TestResourceLogsSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewResourceLogsSlice() - emptySlice.RemoveIf(func(el ResourceLogs) bool { + emptySlice.RemoveIf(func (el ResourceLogs) bool { t.Fail() return false }) @@ -128,13 +128,14 @@ func TestResourceLogsSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestResourceLogsSlice() pos := 0 - filtered.RemoveIf(func(el ResourceLogs) bool { + filtered.RemoveIf(func (el ResourceLogs) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestResourceLogs_CopyTo(t *testing.T) { ms := NewResourceLogs() generateTestResourceLogs().CopyTo(ms) @@ -250,7 +251,7 @@ func TestInstrumentationLibraryLogsSlice_MoveAndAppendTo(t *testing.T) { func TestInstrumentationLibraryLogsSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewInstrumentationLibraryLogsSlice() - emptySlice.RemoveIf(func(el InstrumentationLibraryLogs) bool { + emptySlice.RemoveIf(func (el InstrumentationLibraryLogs) bool { t.Fail() return false }) @@ -258,13 +259,14 @@ func TestInstrumentationLibraryLogsSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestInstrumentationLibraryLogsSlice() pos := 0 - filtered.RemoveIf(func(el InstrumentationLibraryLogs) bool { + filtered.RemoveIf(func (el InstrumentationLibraryLogs) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestInstrumentationLibraryLogs_CopyTo(t *testing.T) { ms := NewInstrumentationLibraryLogs() generateTestInstrumentationLibraryLogs().CopyTo(ms) @@ -380,7 +382,7 @@ func TestLogSlice_MoveAndAppendTo(t *testing.T) { func TestLogSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewLogSlice() - emptySlice.RemoveIf(func(el LogRecord) bool { + emptySlice.RemoveIf(func (el LogRecord) bool { t.Fail() return false }) @@ -388,13 +390,14 @@ func TestLogSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestLogSlice() pos := 0 - filtered.RemoveIf(func(el LogRecord) bool { + filtered.RemoveIf(func (el LogRecord) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestLogRecord_CopyTo(t *testing.T) { ms := NewLogRecord() generateTestLogRecord().CopyTo(ms) diff --git a/model/pdata/generated_metrics.go b/model/pdata/generated_metrics.go index c0a3d048065..013ea7803c2 100644 --- a/model/pdata/generated_metrics.go +++ b/model/pdata/generated_metrics.go @@ -18,6 +18,8 @@ package pdata import ( + "sort" + otlpmetrics "go.opentelemetry.io/collector/model/internal/data/protogen/metrics/v1" ) @@ -112,6 +114,15 @@ func (es ResourceMetricsSlice) AppendEmpty() ResourceMetrics { return es.At(es.Len() - 1) } +// Sort sorts the ResourceMetrics elements within ResourceMetricsSlice given the +// provided less function so that two instances can be compared. +// +// Returns the same instance to allow nicer code like: +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +func (es ResourceMetricsSlice) Sort(less func(i, j int) bool) ResourceMetricsSlice { + sort.SliceStable(*es.orig, less) + return es +} // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ResourceMetricsSlice) MoveAndAppendTo(dest ResourceMetricsSlice) { @@ -273,6 +284,15 @@ func (es InstrumentationLibraryMetricsSlice) AppendEmpty() InstrumentationLibrar return es.At(es.Len() - 1) } +// Sort sorts the InstrumentationLibraryMetrics elements within InstrumentationLibraryMetricsSlice given the +// provided less function so that two instances can be compared. +// +// Returns the same instance to allow nicer code like: +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +func (es InstrumentationLibraryMetricsSlice) Sort(less func(i, j int) bool) InstrumentationLibraryMetricsSlice { + sort.SliceStable(*es.orig, less) + return es +} // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es InstrumentationLibraryMetricsSlice) MoveAndAppendTo(dest InstrumentationLibraryMetricsSlice) { @@ -434,6 +454,15 @@ func (es MetricSlice) AppendEmpty() Metric { return es.At(es.Len() - 1) } +// Sort sorts the Metric elements within MetricSlice given the +// provided less function so that two instances can be compared. +// +// Returns the same instance to allow nicer code like: +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +func (es MetricSlice) Sort(less func(i, j int) bool) MetricSlice { + sort.SliceStable(*es.orig, less) + return es +} // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es MetricSlice) MoveAndAppendTo(dest MetricSlice) { @@ -519,6 +548,8 @@ func (ms Metric) SetUnit(v string) { (*ms.orig).Unit = v } + + // CopyTo copies all properties from the current struct to the dest. func (ms Metric) CopyTo(dest Metric) { dest.SetName(ms.Name()) @@ -865,6 +896,15 @@ func (es IntDataPointSlice) AppendEmpty() IntDataPoint { return es.At(es.Len() - 1) } +// Sort sorts the IntDataPoint elements within IntDataPointSlice given the +// provided less function so that two instances can be compared. +// +// Returns the same instance to allow nicer code like: +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +func (es IntDataPointSlice) Sort(less func(i, j int) bool) IntDataPointSlice { + sort.SliceStable(*es.orig, less) + return es +} // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es IntDataPointSlice) MoveAndAppendTo(dest IntDataPointSlice) { @@ -1059,6 +1099,15 @@ func (es NumberDataPointSlice) AppendEmpty() NumberDataPoint { return es.At(es.Len() - 1) } +// Sort sorts the NumberDataPoint elements within NumberDataPointSlice given the +// provided less function so that two instances can be compared. +// +// Returns the same instance to allow nicer code like: +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +func (es NumberDataPointSlice) Sort(less func(i, j int) bool) NumberDataPointSlice { + sort.SliceStable(*es.orig, less) + return es +} // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es NumberDataPointSlice) MoveAndAppendTo(dest NumberDataPointSlice) { @@ -1255,6 +1304,15 @@ func (es HistogramDataPointSlice) AppendEmpty() HistogramDataPoint { return es.At(es.Len() - 1) } +// Sort sorts the HistogramDataPoint elements within HistogramDataPointSlice given the +// provided less function so that two instances can be compared. +// +// Returns the same instance to allow nicer code like: +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +func (es HistogramDataPointSlice) Sort(less func(i, j int) bool) HistogramDataPointSlice { + sort.SliceStable(*es.orig, less) + return es +} // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es HistogramDataPointSlice) MoveAndAppendTo(dest HistogramDataPointSlice) { @@ -1482,6 +1540,15 @@ func (es SummaryDataPointSlice) AppendEmpty() SummaryDataPoint { return es.At(es.Len() - 1) } +// Sort sorts the SummaryDataPoint elements within SummaryDataPointSlice given the +// provided less function so that two instances can be compared. +// +// Returns the same instance to allow nicer code like: +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +func (es SummaryDataPointSlice) Sort(less func(i, j int) bool) SummaryDataPointSlice { + sort.SliceStable(*es.orig, less) + return es +} // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es SummaryDataPointSlice) MoveAndAppendTo(dest SummaryDataPointSlice) { @@ -1687,6 +1754,15 @@ func (es ValueAtQuantileSlice) AppendEmpty() ValueAtQuantile { return es.At(es.Len() - 1) } +// Sort sorts the ValueAtQuantile elements within ValueAtQuantileSlice given the +// provided less function so that two instances can be compared. +// +// Returns the same instance to allow nicer code like: +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +func (es ValueAtQuantileSlice) Sort(less func(i, j int) bool) ValueAtQuantileSlice { + sort.SliceStable(*es.orig, less) + return es +} // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ValueAtQuantileSlice) MoveAndAppendTo(dest ValueAtQuantileSlice) { @@ -1852,7 +1928,6 @@ func (es IntExemplarSlice) AppendEmpty() IntExemplar { *es.orig = append(*es.orig, otlpmetrics.IntExemplar{}) return es.At(es.Len() - 1) } - // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es IntExemplarSlice) MoveAndAppendTo(dest IntExemplarSlice) { @@ -2027,7 +2102,6 @@ func (es ExemplarSlice) AppendEmpty() Exemplar { *es.orig = append(*es.orig, otlpmetrics.Exemplar{}) return es.At(es.Len() - 1) } - // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ExemplarSlice) MoveAndAppendTo(dest ExemplarSlice) { diff --git a/model/pdata/generated_metrics_test.go b/model/pdata/generated_metrics_test.go index 225f19e8381..16ddc9952a7 100644 --- a/model/pdata/generated_metrics_test.go +++ b/model/pdata/generated_metrics_test.go @@ -120,7 +120,7 @@ func TestResourceMetricsSlice_MoveAndAppendTo(t *testing.T) { func TestResourceMetricsSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewResourceMetricsSlice() - emptySlice.RemoveIf(func(el ResourceMetrics) bool { + emptySlice.RemoveIf(func (el ResourceMetrics) bool { t.Fail() return false }) @@ -128,13 +128,14 @@ func TestResourceMetricsSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestResourceMetricsSlice() pos := 0 - filtered.RemoveIf(func(el ResourceMetrics) bool { + filtered.RemoveIf(func (el ResourceMetrics) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestResourceMetrics_CopyTo(t *testing.T) { ms := NewResourceMetrics() generateTestResourceMetrics().CopyTo(ms) @@ -250,7 +251,7 @@ func TestInstrumentationLibraryMetricsSlice_MoveAndAppendTo(t *testing.T) { func TestInstrumentationLibraryMetricsSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewInstrumentationLibraryMetricsSlice() - emptySlice.RemoveIf(func(el InstrumentationLibraryMetrics) bool { + emptySlice.RemoveIf(func (el InstrumentationLibraryMetrics) bool { t.Fail() return false }) @@ -258,13 +259,14 @@ func TestInstrumentationLibraryMetricsSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestInstrumentationLibraryMetricsSlice() pos := 0 - filtered.RemoveIf(func(el InstrumentationLibraryMetrics) bool { + filtered.RemoveIf(func (el InstrumentationLibraryMetrics) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestInstrumentationLibraryMetrics_CopyTo(t *testing.T) { ms := NewInstrumentationLibraryMetrics() generateTestInstrumentationLibraryMetrics().CopyTo(ms) @@ -380,7 +382,7 @@ func TestMetricSlice_MoveAndAppendTo(t *testing.T) { func TestMetricSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewMetricSlice() - emptySlice.RemoveIf(func(el Metric) bool { + emptySlice.RemoveIf(func (el Metric) bool { t.Fail() return false }) @@ -388,13 +390,14 @@ func TestMetricSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestMetricSlice() pos := 0 - filtered.RemoveIf(func(el Metric) bool { + filtered.RemoveIf(func (el Metric) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestMetric_CopyTo(t *testing.T) { ms := NewMetric() generateTestMetric().CopyTo(ms) @@ -425,6 +428,9 @@ func TestMetric_Unit(t *testing.T) { assert.EqualValues(t, testValUnit, ms.Unit()) } + + + func TestIntGauge_CopyTo(t *testing.T) { ms := NewIntGauge() generateTestIntGauge().CopyTo(ms) @@ -439,6 +445,7 @@ func TestIntGauge_DataPoints(t *testing.T) { assert.EqualValues(t, testValDataPoints, ms.DataPoints()) } + func TestGauge_CopyTo(t *testing.T) { ms := NewGauge() generateTestGauge().CopyTo(ms) @@ -453,6 +460,7 @@ func TestGauge_DataPoints(t *testing.T) { assert.EqualValues(t, testValDataPoints, ms.DataPoints()) } + func TestIntSum_CopyTo(t *testing.T) { ms := NewIntSum() generateTestIntSum().CopyTo(ms) @@ -483,6 +491,7 @@ func TestIntSum_DataPoints(t *testing.T) { assert.EqualValues(t, testValDataPoints, ms.DataPoints()) } + func TestSum_CopyTo(t *testing.T) { ms := NewSum() generateTestSum().CopyTo(ms) @@ -513,6 +522,7 @@ func TestSum_DataPoints(t *testing.T) { assert.EqualValues(t, testValDataPoints, ms.DataPoints()) } + func TestHistogram_CopyTo(t *testing.T) { ms := NewHistogram() generateTestHistogram().CopyTo(ms) @@ -535,6 +545,7 @@ func TestHistogram_DataPoints(t *testing.T) { assert.EqualValues(t, testValDataPoints, ms.DataPoints()) } + func TestSummary_CopyTo(t *testing.T) { ms := NewSummary() generateTestSummary().CopyTo(ms) @@ -644,7 +655,7 @@ func TestIntDataPointSlice_MoveAndAppendTo(t *testing.T) { func TestIntDataPointSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewIntDataPointSlice() - emptySlice.RemoveIf(func(el IntDataPoint) bool { + emptySlice.RemoveIf(func (el IntDataPoint) bool { t.Fail() return false }) @@ -652,13 +663,14 @@ func TestIntDataPointSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestIntDataPointSlice() pos := 0 - filtered.RemoveIf(func(el IntDataPoint) bool { + filtered.RemoveIf(func (el IntDataPoint) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestIntDataPoint_CopyTo(t *testing.T) { ms := NewIntDataPoint() generateTestIntDataPoint().CopyTo(ms) @@ -800,7 +812,7 @@ func TestNumberDataPointSlice_MoveAndAppendTo(t *testing.T) { func TestNumberDataPointSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewNumberDataPointSlice() - emptySlice.RemoveIf(func(el NumberDataPoint) bool { + emptySlice.RemoveIf(func (el NumberDataPoint) bool { t.Fail() return false }) @@ -808,13 +820,14 @@ func TestNumberDataPointSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestNumberDataPointSlice() pos := 0 - filtered.RemoveIf(func(el NumberDataPoint) bool { + filtered.RemoveIf(func (el NumberDataPoint) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestNumberDataPoint_CopyTo(t *testing.T) { ms := NewNumberDataPoint() generateTestNumberDataPoint().CopyTo(ms) @@ -956,7 +969,7 @@ func TestHistogramDataPointSlice_MoveAndAppendTo(t *testing.T) { func TestHistogramDataPointSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewHistogramDataPointSlice() - emptySlice.RemoveIf(func(el HistogramDataPoint) bool { + emptySlice.RemoveIf(func (el HistogramDataPoint) bool { t.Fail() return false }) @@ -964,13 +977,14 @@ func TestHistogramDataPointSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestHistogramDataPointSlice() pos := 0 - filtered.RemoveIf(func(el HistogramDataPoint) bool { + filtered.RemoveIf(func (el HistogramDataPoint) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestHistogramDataPoint_CopyTo(t *testing.T) { ms := NewHistogramDataPoint() generateTestHistogramDataPoint().CopyTo(ms) @@ -1136,7 +1150,7 @@ func TestSummaryDataPointSlice_MoveAndAppendTo(t *testing.T) { func TestSummaryDataPointSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewSummaryDataPointSlice() - emptySlice.RemoveIf(func(el SummaryDataPoint) bool { + emptySlice.RemoveIf(func (el SummaryDataPoint) bool { t.Fail() return false }) @@ -1144,13 +1158,14 @@ func TestSummaryDataPointSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestSummaryDataPointSlice() pos := 0 - filtered.RemoveIf(func(el SummaryDataPoint) bool { + filtered.RemoveIf(func (el SummaryDataPoint) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestSummaryDataPoint_CopyTo(t *testing.T) { ms := NewSummaryDataPoint() generateTestSummaryDataPoint().CopyTo(ms) @@ -1300,7 +1315,7 @@ func TestValueAtQuantileSlice_MoveAndAppendTo(t *testing.T) { func TestValueAtQuantileSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewValueAtQuantileSlice() - emptySlice.RemoveIf(func(el ValueAtQuantile) bool { + emptySlice.RemoveIf(func (el ValueAtQuantile) bool { t.Fail() return false }) @@ -1308,13 +1323,14 @@ func TestValueAtQuantileSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestValueAtQuantileSlice() pos := 0 - filtered.RemoveIf(func(el ValueAtQuantile) bool { + filtered.RemoveIf(func (el ValueAtQuantile) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestValueAtQuantile_CopyTo(t *testing.T) { ms := NewValueAtQuantile() generateTestValueAtQuantile().CopyTo(ms) @@ -1423,7 +1439,7 @@ func TestIntExemplarSlice_MoveAndAppendTo(t *testing.T) { func TestIntExemplarSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewIntExemplarSlice() - emptySlice.RemoveIf(func(el IntExemplar) bool { + emptySlice.RemoveIf(func (el IntExemplar) bool { t.Fail() return false }) @@ -1431,13 +1447,14 @@ func TestIntExemplarSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestIntExemplarSlice() pos := 0 - filtered.RemoveIf(func(el IntExemplar) bool { + filtered.RemoveIf(func (el IntExemplar) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestIntExemplar_CopyTo(t *testing.T) { ms := NewIntExemplar() generateTestIntExemplar().CopyTo(ms) @@ -1554,7 +1571,7 @@ func TestExemplarSlice_MoveAndAppendTo(t *testing.T) { func TestExemplarSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewExemplarSlice() - emptySlice.RemoveIf(func(el Exemplar) bool { + emptySlice.RemoveIf(func (el Exemplar) bool { t.Fail() return false }) @@ -1562,13 +1579,14 @@ func TestExemplarSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestExemplarSlice() pos := 0 - filtered.RemoveIf(func(el Exemplar) bool { + filtered.RemoveIf(func (el Exemplar) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestExemplar_CopyTo(t *testing.T) { ms := NewExemplar() generateTestExemplar().CopyTo(ms) diff --git a/model/pdata/generated_resource_test.go b/model/pdata/generated_resource_test.go index cff3992e35f..b96b74e5fa7 100644 --- a/model/pdata/generated_resource_test.go +++ b/model/pdata/generated_resource_test.go @@ -23,6 +23,7 @@ import ( "github.com/stretchr/testify/assert" ) + func TestResource_CopyTo(t *testing.T) { ms := NewResource() generateTestResource().CopyTo(ms) diff --git a/model/pdata/generated_trace.go b/model/pdata/generated_trace.go index 845da62f448..42855bbf159 100644 --- a/model/pdata/generated_trace.go +++ b/model/pdata/generated_trace.go @@ -18,6 +18,8 @@ package pdata import ( + "sort" + otlptrace "go.opentelemetry.io/collector/model/internal/data/protogen/trace/v1" ) @@ -112,6 +114,15 @@ func (es ResourceSpansSlice) AppendEmpty() ResourceSpans { return es.At(es.Len() - 1) } +// Sort sorts the ResourceSpans elements within ResourceSpansSlice given the +// provided less function so that two instances can be compared. +// +// Returns the same instance to allow nicer code like: +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +func (es ResourceSpansSlice) Sort(less func(i, j int) bool) ResourceSpansSlice { + sort.SliceStable(*es.orig, less) + return es +} // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ResourceSpansSlice) MoveAndAppendTo(dest ResourceSpansSlice) { @@ -273,6 +284,15 @@ func (es InstrumentationLibrarySpansSlice) AppendEmpty() InstrumentationLibraryS return es.At(es.Len() - 1) } +// Sort sorts the InstrumentationLibrarySpans elements within InstrumentationLibrarySpansSlice given the +// provided less function so that two instances can be compared. +// +// Returns the same instance to allow nicer code like: +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +func (es InstrumentationLibrarySpansSlice) Sort(less func(i, j int) bool) InstrumentationLibrarySpansSlice { + sort.SliceStable(*es.orig, less) + return es +} // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es InstrumentationLibrarySpansSlice) MoveAndAppendTo(dest InstrumentationLibrarySpansSlice) { @@ -434,6 +454,15 @@ func (es SpanSlice) AppendEmpty() Span { return es.At(es.Len() - 1) } +// Sort sorts the Span elements within SpanSlice given the +// provided less function so that two instances can be compared. +// +// Returns the same instance to allow nicer code like: +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +func (es SpanSlice) Sort(less func(i, j int) bool) SpanSlice { + sort.SliceStable(*es.orig, less) + return es +} // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es SpanSlice) MoveAndAppendTo(dest SpanSlice) { @@ -729,6 +758,15 @@ func (es SpanEventSlice) AppendEmpty() SpanEvent { return es.At(es.Len() - 1) } +// Sort sorts the SpanEvent elements within SpanEventSlice given the +// provided less function so that two instances can be compared. +// +// Returns the same instance to allow nicer code like: +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +func (es SpanEventSlice) Sort(less func(i, j int) bool) SpanEventSlice { + sort.SliceStable(*es.orig, less) + return es +} // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es SpanEventSlice) MoveAndAppendTo(dest SpanEventSlice) { @@ -918,6 +956,15 @@ func (es SpanLinkSlice) AppendEmpty() SpanLink { return es.At(es.Len() - 1) } +// Sort sorts the SpanLink elements within SpanLinkSlice given the +// provided less function so that two instances can be compared. +// +// Returns the same instance to allow nicer code like: +// assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) +func (es SpanLinkSlice) Sort(less func(i, j int) bool) SpanLinkSlice { + sort.SliceStable(*es.orig, less) + return es +} // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es SpanLinkSlice) MoveAndAppendTo(dest SpanLinkSlice) { diff --git a/model/pdata/generated_trace_test.go b/model/pdata/generated_trace_test.go index b7de1f73721..8f14e7bbcbe 100644 --- a/model/pdata/generated_trace_test.go +++ b/model/pdata/generated_trace_test.go @@ -120,7 +120,7 @@ func TestResourceSpansSlice_MoveAndAppendTo(t *testing.T) { func TestResourceSpansSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewResourceSpansSlice() - emptySlice.RemoveIf(func(el ResourceSpans) bool { + emptySlice.RemoveIf(func (el ResourceSpans) bool { t.Fail() return false }) @@ -128,13 +128,14 @@ func TestResourceSpansSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestResourceSpansSlice() pos := 0 - filtered.RemoveIf(func(el ResourceSpans) bool { + filtered.RemoveIf(func (el ResourceSpans) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestResourceSpans_CopyTo(t *testing.T) { ms := NewResourceSpans() generateTestResourceSpans().CopyTo(ms) @@ -250,7 +251,7 @@ func TestInstrumentationLibrarySpansSlice_MoveAndAppendTo(t *testing.T) { func TestInstrumentationLibrarySpansSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewInstrumentationLibrarySpansSlice() - emptySlice.RemoveIf(func(el InstrumentationLibrarySpans) bool { + emptySlice.RemoveIf(func (el InstrumentationLibrarySpans) bool { t.Fail() return false }) @@ -258,13 +259,14 @@ func TestInstrumentationLibrarySpansSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestInstrumentationLibrarySpansSlice() pos := 0 - filtered.RemoveIf(func(el InstrumentationLibrarySpans) bool { + filtered.RemoveIf(func (el InstrumentationLibrarySpans) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestInstrumentationLibrarySpans_CopyTo(t *testing.T) { ms := NewInstrumentationLibrarySpans() generateTestInstrumentationLibrarySpans().CopyTo(ms) @@ -380,7 +382,7 @@ func TestSpanSlice_MoveAndAppendTo(t *testing.T) { func TestSpanSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewSpanSlice() - emptySlice.RemoveIf(func(el Span) bool { + emptySlice.RemoveIf(func (el Span) bool { t.Fail() return false }) @@ -388,13 +390,14 @@ func TestSpanSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestSpanSlice() pos := 0 - filtered.RemoveIf(func(el Span) bool { + filtered.RemoveIf(func (el Span) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestSpan_CopyTo(t *testing.T) { ms := NewSpan() generateTestSpan().CopyTo(ms) @@ -614,7 +617,7 @@ func TestSpanEventSlice_MoveAndAppendTo(t *testing.T) { func TestSpanEventSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewSpanEventSlice() - emptySlice.RemoveIf(func(el SpanEvent) bool { + emptySlice.RemoveIf(func (el SpanEvent) bool { t.Fail() return false }) @@ -622,13 +625,14 @@ func TestSpanEventSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestSpanEventSlice() pos := 0 - filtered.RemoveIf(func(el SpanEvent) bool { + filtered.RemoveIf(func (el SpanEvent) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestSpanEvent_CopyTo(t *testing.T) { ms := NewSpanEvent() generateTestSpanEvent().CopyTo(ms) @@ -762,7 +766,7 @@ func TestSpanLinkSlice_MoveAndAppendTo(t *testing.T) { func TestSpanLinkSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewSpanLinkSlice() - emptySlice.RemoveIf(func(el SpanLink) bool { + emptySlice.RemoveIf(func (el SpanLink) bool { t.Fail() return false }) @@ -770,13 +774,14 @@ func TestSpanLinkSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestSpanLinkSlice() pos := 0 - filtered.RemoveIf(func(el SpanLink) bool { + filtered.RemoveIf(func (el SpanLink) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } + func TestSpanLink_CopyTo(t *testing.T) { ms := NewSpanLink() generateTestSpanLink().CopyTo(ms) @@ -823,6 +828,7 @@ func TestSpanLink_DroppedAttributesCount(t *testing.T) { assert.EqualValues(t, testValDroppedAttributesCount, ms.DroppedAttributesCount()) } + func TestSpanStatus_CopyTo(t *testing.T) { ms := NewSpanStatus() generateTestSpanStatus().CopyTo(ms) From 5458d80bf409fac1d7c4674cb31fc36ec214b3a1 Mon Sep 17 00:00:00 2001 From: Jacob Marble Date: Tue, 20 Jul 2021 16:48:20 -0700 Subject: [PATCH 2/4] fix: improve TypeSlice.Sort(less) signature --- cmd/pdatagen/internal/base_slices.go | 13 ++-- model/pdata/generated_log.go | 33 ++++++++--- model/pdata/generated_metrics.go | 88 ++++++++++++++++++++-------- model/pdata/generated_trace.go | 55 ++++++++++++----- 4 files changed, 137 insertions(+), 52 deletions(-) diff --git a/cmd/pdatagen/internal/base_slices.go b/cmd/pdatagen/internal/base_slices.go index 27316cb44e6..45cf6b901b4 100644 --- a/cmd/pdatagen/internal/base_slices.go +++ b/cmd/pdatagen/internal/base_slices.go @@ -203,14 +203,19 @@ func (es ${structName}) AppendEmpty() ${elementName} { } // Sort sorts the ${elementName} elements within ${structName} given the -// provided less function so that two instances can be compared. +// provided less function so that two instances of ${structName} +// can be compared. // // Returns the same instance to allow nicer code like: +// lessFunc := func(a, b ${elementName}) bool { +// return a.Name() < b.Name() // choose any comparison here +// } // assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) -func (es ${structName}) Sort(less func(i, j int) bool) ${structName} { - sort.SliceStable(*es.orig, less) +func (es ${structName}) Sort(less func(a, b ${elementName}) bool) ${structName} { + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es -}` +} +` const slicePtrTestTemplate = `func Test${structName}(t *testing.T) { es := New${structName}() diff --git a/model/pdata/generated_log.go b/model/pdata/generated_log.go index 104e23d10fd..24292f1927a 100644 --- a/model/pdata/generated_log.go +++ b/model/pdata/generated_log.go @@ -115,14 +115,19 @@ func (es ResourceLogsSlice) AppendEmpty() ResourceLogs { } // Sort sorts the ResourceLogs elements within ResourceLogsSlice given the -// provided less function so that two instances can be compared. +// provided less function so that two instances of ResourceLogsSlice +// can be compared. // // Returns the same instance to allow nicer code like: +// lessFunc := func(a, b ResourceLogs) bool { +// return a.Name() < b.Name() // choose any comparison here +// } // assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) -func (es ResourceLogsSlice) Sort(less func(i, j int) bool) ResourceLogsSlice { - sort.SliceStable(*es.orig, less) +func (es ResourceLogsSlice) Sort(less func(a, b ResourceLogs) bool) ResourceLogsSlice { + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ResourceLogsSlice) MoveAndAppendTo(dest ResourceLogsSlice) { @@ -285,14 +290,19 @@ func (es InstrumentationLibraryLogsSlice) AppendEmpty() InstrumentationLibraryLo } // Sort sorts the InstrumentationLibraryLogs elements within InstrumentationLibraryLogsSlice given the -// provided less function so that two instances can be compared. +// provided less function so that two instances of InstrumentationLibraryLogsSlice +// can be compared. // // Returns the same instance to allow nicer code like: +// lessFunc := func(a, b InstrumentationLibraryLogs) bool { +// return a.Name() < b.Name() // choose any comparison here +// } // assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) -func (es InstrumentationLibraryLogsSlice) Sort(less func(i, j int) bool) InstrumentationLibraryLogsSlice { - sort.SliceStable(*es.orig, less) +func (es InstrumentationLibraryLogsSlice) Sort(less func(a, b InstrumentationLibraryLogs) bool) InstrumentationLibraryLogsSlice { + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es InstrumentationLibraryLogsSlice) MoveAndAppendTo(dest InstrumentationLibraryLogsSlice) { @@ -455,14 +465,19 @@ func (es LogSlice) AppendEmpty() LogRecord { } // Sort sorts the LogRecord elements within LogSlice given the -// provided less function so that two instances can be compared. +// provided less function so that two instances of LogSlice +// can be compared. // // Returns the same instance to allow nicer code like: +// lessFunc := func(a, b LogRecord) bool { +// return a.Name() < b.Name() // choose any comparison here +// } // assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) -func (es LogSlice) Sort(less func(i, j int) bool) LogSlice { - sort.SliceStable(*es.orig, less) +func (es LogSlice) Sort(less func(a, b LogRecord) bool) LogSlice { + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es LogSlice) MoveAndAppendTo(dest LogSlice) { diff --git a/model/pdata/generated_metrics.go b/model/pdata/generated_metrics.go index 013ea7803c2..89978573afd 100644 --- a/model/pdata/generated_metrics.go +++ b/model/pdata/generated_metrics.go @@ -115,14 +115,19 @@ func (es ResourceMetricsSlice) AppendEmpty() ResourceMetrics { } // Sort sorts the ResourceMetrics elements within ResourceMetricsSlice given the -// provided less function so that two instances can be compared. +// provided less function so that two instances of ResourceMetricsSlice +// can be compared. // // Returns the same instance to allow nicer code like: +// lessFunc := func(a, b ResourceMetrics) bool { +// return a.Name() < b.Name() // choose any comparison here +// } // assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) -func (es ResourceMetricsSlice) Sort(less func(i, j int) bool) ResourceMetricsSlice { - sort.SliceStable(*es.orig, less) +func (es ResourceMetricsSlice) Sort(less func(a, b ResourceMetrics) bool) ResourceMetricsSlice { + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ResourceMetricsSlice) MoveAndAppendTo(dest ResourceMetricsSlice) { @@ -285,14 +290,19 @@ func (es InstrumentationLibraryMetricsSlice) AppendEmpty() InstrumentationLibrar } // Sort sorts the InstrumentationLibraryMetrics elements within InstrumentationLibraryMetricsSlice given the -// provided less function so that two instances can be compared. +// provided less function so that two instances of InstrumentationLibraryMetricsSlice +// can be compared. // // Returns the same instance to allow nicer code like: +// lessFunc := func(a, b InstrumentationLibraryMetrics) bool { +// return a.Name() < b.Name() // choose any comparison here +// } // assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) -func (es InstrumentationLibraryMetricsSlice) Sort(less func(i, j int) bool) InstrumentationLibraryMetricsSlice { - sort.SliceStable(*es.orig, less) +func (es InstrumentationLibraryMetricsSlice) Sort(less func(a, b InstrumentationLibraryMetrics) bool) InstrumentationLibraryMetricsSlice { + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es InstrumentationLibraryMetricsSlice) MoveAndAppendTo(dest InstrumentationLibraryMetricsSlice) { @@ -455,14 +465,19 @@ func (es MetricSlice) AppendEmpty() Metric { } // Sort sorts the Metric elements within MetricSlice given the -// provided less function so that two instances can be compared. +// provided less function so that two instances of MetricSlice +// can be compared. // // Returns the same instance to allow nicer code like: +// lessFunc := func(a, b Metric) bool { +// return a.Name() < b.Name() // choose any comparison here +// } // assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) -func (es MetricSlice) Sort(less func(i, j int) bool) MetricSlice { - sort.SliceStable(*es.orig, less) +func (es MetricSlice) Sort(less func(a, b Metric) bool) MetricSlice { + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es MetricSlice) MoveAndAppendTo(dest MetricSlice) { @@ -897,14 +912,19 @@ func (es IntDataPointSlice) AppendEmpty() IntDataPoint { } // Sort sorts the IntDataPoint elements within IntDataPointSlice given the -// provided less function so that two instances can be compared. +// provided less function so that two instances of IntDataPointSlice +// can be compared. // // Returns the same instance to allow nicer code like: +// lessFunc := func(a, b IntDataPoint) bool { +// return a.Name() < b.Name() // choose any comparison here +// } // assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) -func (es IntDataPointSlice) Sort(less func(i, j int) bool) IntDataPointSlice { - sort.SliceStable(*es.orig, less) +func (es IntDataPointSlice) Sort(less func(a, b IntDataPoint) bool) IntDataPointSlice { + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es IntDataPointSlice) MoveAndAppendTo(dest IntDataPointSlice) { @@ -1100,14 +1120,19 @@ func (es NumberDataPointSlice) AppendEmpty() NumberDataPoint { } // Sort sorts the NumberDataPoint elements within NumberDataPointSlice given the -// provided less function so that two instances can be compared. +// provided less function so that two instances of NumberDataPointSlice +// can be compared. // // Returns the same instance to allow nicer code like: +// lessFunc := func(a, b NumberDataPoint) bool { +// return a.Name() < b.Name() // choose any comparison here +// } // assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) -func (es NumberDataPointSlice) Sort(less func(i, j int) bool) NumberDataPointSlice { - sort.SliceStable(*es.orig, less) +func (es NumberDataPointSlice) Sort(less func(a, b NumberDataPoint) bool) NumberDataPointSlice { + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es NumberDataPointSlice) MoveAndAppendTo(dest NumberDataPointSlice) { @@ -1305,14 +1330,19 @@ func (es HistogramDataPointSlice) AppendEmpty() HistogramDataPoint { } // Sort sorts the HistogramDataPoint elements within HistogramDataPointSlice given the -// provided less function so that two instances can be compared. +// provided less function so that two instances of HistogramDataPointSlice +// can be compared. // // Returns the same instance to allow nicer code like: +// lessFunc := func(a, b HistogramDataPoint) bool { +// return a.Name() < b.Name() // choose any comparison here +// } // assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) -func (es HistogramDataPointSlice) Sort(less func(i, j int) bool) HistogramDataPointSlice { - sort.SliceStable(*es.orig, less) +func (es HistogramDataPointSlice) Sort(less func(a, b HistogramDataPoint) bool) HistogramDataPointSlice { + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es HistogramDataPointSlice) MoveAndAppendTo(dest HistogramDataPointSlice) { @@ -1541,14 +1571,19 @@ func (es SummaryDataPointSlice) AppendEmpty() SummaryDataPoint { } // Sort sorts the SummaryDataPoint elements within SummaryDataPointSlice given the -// provided less function so that two instances can be compared. +// provided less function so that two instances of SummaryDataPointSlice +// can be compared. // // Returns the same instance to allow nicer code like: +// lessFunc := func(a, b SummaryDataPoint) bool { +// return a.Name() < b.Name() // choose any comparison here +// } // assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) -func (es SummaryDataPointSlice) Sort(less func(i, j int) bool) SummaryDataPointSlice { - sort.SliceStable(*es.orig, less) +func (es SummaryDataPointSlice) Sort(less func(a, b SummaryDataPoint) bool) SummaryDataPointSlice { + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es SummaryDataPointSlice) MoveAndAppendTo(dest SummaryDataPointSlice) { @@ -1755,14 +1790,19 @@ func (es ValueAtQuantileSlice) AppendEmpty() ValueAtQuantile { } // Sort sorts the ValueAtQuantile elements within ValueAtQuantileSlice given the -// provided less function so that two instances can be compared. +// provided less function so that two instances of ValueAtQuantileSlice +// can be compared. // // Returns the same instance to allow nicer code like: +// lessFunc := func(a, b ValueAtQuantile) bool { +// return a.Name() < b.Name() // choose any comparison here +// } // assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) -func (es ValueAtQuantileSlice) Sort(less func(i, j int) bool) ValueAtQuantileSlice { - sort.SliceStable(*es.orig, less) +func (es ValueAtQuantileSlice) Sort(less func(a, b ValueAtQuantile) bool) ValueAtQuantileSlice { + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ValueAtQuantileSlice) MoveAndAppendTo(dest ValueAtQuantileSlice) { diff --git a/model/pdata/generated_trace.go b/model/pdata/generated_trace.go index 42855bbf159..2359b769d03 100644 --- a/model/pdata/generated_trace.go +++ b/model/pdata/generated_trace.go @@ -115,14 +115,19 @@ func (es ResourceSpansSlice) AppendEmpty() ResourceSpans { } // Sort sorts the ResourceSpans elements within ResourceSpansSlice given the -// provided less function so that two instances can be compared. +// provided less function so that two instances of ResourceSpansSlice +// can be compared. // // Returns the same instance to allow nicer code like: +// lessFunc := func(a, b ResourceSpans) bool { +// return a.Name() < b.Name() // choose any comparison here +// } // assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) -func (es ResourceSpansSlice) Sort(less func(i, j int) bool) ResourceSpansSlice { - sort.SliceStable(*es.orig, less) +func (es ResourceSpansSlice) Sort(less func(a, b ResourceSpans) bool) ResourceSpansSlice { + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ResourceSpansSlice) MoveAndAppendTo(dest ResourceSpansSlice) { @@ -285,14 +290,19 @@ func (es InstrumentationLibrarySpansSlice) AppendEmpty() InstrumentationLibraryS } // Sort sorts the InstrumentationLibrarySpans elements within InstrumentationLibrarySpansSlice given the -// provided less function so that two instances can be compared. +// provided less function so that two instances of InstrumentationLibrarySpansSlice +// can be compared. // // Returns the same instance to allow nicer code like: +// lessFunc := func(a, b InstrumentationLibrarySpans) bool { +// return a.Name() < b.Name() // choose any comparison here +// } // assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) -func (es InstrumentationLibrarySpansSlice) Sort(less func(i, j int) bool) InstrumentationLibrarySpansSlice { - sort.SliceStable(*es.orig, less) +func (es InstrumentationLibrarySpansSlice) Sort(less func(a, b InstrumentationLibrarySpans) bool) InstrumentationLibrarySpansSlice { + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es InstrumentationLibrarySpansSlice) MoveAndAppendTo(dest InstrumentationLibrarySpansSlice) { @@ -455,14 +465,19 @@ func (es SpanSlice) AppendEmpty() Span { } // Sort sorts the Span elements within SpanSlice given the -// provided less function so that two instances can be compared. +// provided less function so that two instances of SpanSlice +// can be compared. // // Returns the same instance to allow nicer code like: +// lessFunc := func(a, b Span) bool { +// return a.Name() < b.Name() // choose any comparison here +// } // assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) -func (es SpanSlice) Sort(less func(i, j int) bool) SpanSlice { - sort.SliceStable(*es.orig, less) +func (es SpanSlice) Sort(less func(a, b Span) bool) SpanSlice { + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es SpanSlice) MoveAndAppendTo(dest SpanSlice) { @@ -759,14 +774,19 @@ func (es SpanEventSlice) AppendEmpty() SpanEvent { } // Sort sorts the SpanEvent elements within SpanEventSlice given the -// provided less function so that two instances can be compared. +// provided less function so that two instances of SpanEventSlice +// can be compared. // // Returns the same instance to allow nicer code like: +// lessFunc := func(a, b SpanEvent) bool { +// return a.Name() < b.Name() // choose any comparison here +// } // assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) -func (es SpanEventSlice) Sort(less func(i, j int) bool) SpanEventSlice { - sort.SliceStable(*es.orig, less) +func (es SpanEventSlice) Sort(less func(a, b SpanEvent) bool) SpanEventSlice { + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es SpanEventSlice) MoveAndAppendTo(dest SpanEventSlice) { @@ -957,14 +977,19 @@ func (es SpanLinkSlice) AppendEmpty() SpanLink { } // Sort sorts the SpanLink elements within SpanLinkSlice given the -// provided less function so that two instances can be compared. +// provided less function so that two instances of SpanLinkSlice +// can be compared. // // Returns the same instance to allow nicer code like: +// lessFunc := func(a, b SpanLink) bool { +// return a.Name() < b.Name() // choose any comparison here +// } // assert.EqualValues(t, expected.Sort(lessFunc), actual.Sort(lessFunc)) -func (es SpanLinkSlice) Sort(less func(i, j int) bool) SpanLinkSlice { - sort.SliceStable(*es.orig, less) +func (es SpanLinkSlice) Sort(less func(a, b SpanLink) bool) SpanLinkSlice { + sort.SliceStable(*es.orig, func(i, j int) bool { return less(es.At(i), es.At(j)) }) return es } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es SpanLinkSlice) MoveAndAppendTo(dest SpanLinkSlice) { From 48ab7da6c71041e341eea2e64d7ed50ab015eabb Mon Sep 17 00:00:00 2001 From: Jacob Marble Date: Wed, 21 Jul 2021 07:28:53 -0700 Subject: [PATCH 3/4] fix: resolve goimports CI check --- cmd/pdatagen/internal/files.go | 8 ++++++-- model/pdata/generated_log.go | 2 +- model/pdata/generated_metrics.go | 2 +- model/pdata/generated_trace.go | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cmd/pdatagen/internal/files.go b/cmd/pdatagen/internal/files.go index 81485b06083..62b9b673c38 100644 --- a/cmd/pdatagen/internal/files.go +++ b/cmd/pdatagen/internal/files.go @@ -62,8 +62,12 @@ func (f *File) GenerateFile() string { sb.WriteString(newLine + newLine) // Add imports sb.WriteString("import (" + newLine) - for _, i := range f.imports { - sb.WriteString("\t" + i + newLine) + for _, imp := range f.imports { + if imp != "" { + sb.WriteString("\t" + imp + newLine) + } else { + sb.WriteString(newLine) + } } sb.WriteString(")") // Write all structs diff --git a/model/pdata/generated_log.go b/model/pdata/generated_log.go index 24292f1927a..a0889ee0d12 100644 --- a/model/pdata/generated_log.go +++ b/model/pdata/generated_log.go @@ -19,7 +19,7 @@ package pdata import ( "sort" - + otlplogs "go.opentelemetry.io/collector/model/internal/data/protogen/logs/v1" ) diff --git a/model/pdata/generated_metrics.go b/model/pdata/generated_metrics.go index 89978573afd..715bc1019d1 100644 --- a/model/pdata/generated_metrics.go +++ b/model/pdata/generated_metrics.go @@ -19,7 +19,7 @@ package pdata import ( "sort" - + otlpmetrics "go.opentelemetry.io/collector/model/internal/data/protogen/metrics/v1" ) diff --git a/model/pdata/generated_trace.go b/model/pdata/generated_trace.go index 2359b769d03..58ccbf76d2b 100644 --- a/model/pdata/generated_trace.go +++ b/model/pdata/generated_trace.go @@ -19,7 +19,7 @@ package pdata import ( "sort" - + otlptrace "go.opentelemetry.io/collector/model/internal/data/protogen/trace/v1" ) From 5474b2c6007998827bcc8da0f13d88b30ce07c76 Mon Sep 17 00:00:00 2001 From: Jacob Marble Date: Wed, 21 Jul 2021 07:55:07 -0700 Subject: [PATCH 4/4] chore: make genpdata --- model/pdata/generated_common.go | 1 + model/pdata/generated_common_test.go | 5 +-- model/pdata/generated_log_test.go | 15 +++---- model/pdata/generated_metrics.go | 4 +- model/pdata/generated_metrics_test.go | 58 +++++++++----------------- model/pdata/generated_resource_test.go | 1 - model/pdata/generated_trace_test.go | 26 +++++------- 7 files changed, 41 insertions(+), 69 deletions(-) diff --git a/model/pdata/generated_common.go b/model/pdata/generated_common.go index 842554f2371..faae97875e7 100644 --- a/model/pdata/generated_common.go +++ b/model/pdata/generated_common.go @@ -154,6 +154,7 @@ func (es AnyValueArray) AppendEmpty() AttributeValue { *es.orig = append(*es.orig, otlpcommon.AnyValue{}) return es.At(es.Len() - 1) } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es AnyValueArray) MoveAndAppendTo(dest AnyValueArray) { diff --git a/model/pdata/generated_common_test.go b/model/pdata/generated_common_test.go index e80280af875..3ef9f668ada 100644 --- a/model/pdata/generated_common_test.go +++ b/model/pdata/generated_common_test.go @@ -25,7 +25,6 @@ import ( otlpcommon "go.opentelemetry.io/collector/model/internal/data/protogen/common/v1" ) - func TestInstrumentationLibrary_CopyTo(t *testing.T) { ms := NewInstrumentationLibrary() generateTestInstrumentationLibrary().CopyTo(ms) @@ -134,7 +133,7 @@ func TestAnyValueArray_MoveAndAppendTo(t *testing.T) { func TestAnyValueArray_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewAnyValueArray() - emptySlice.RemoveIf(func (el AttributeValue) bool { + emptySlice.RemoveIf(func(el AttributeValue) bool { t.Fail() return false }) @@ -142,7 +141,7 @@ func TestAnyValueArray_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestAnyValueArray() pos := 0 - filtered.RemoveIf(func (el AttributeValue) bool { + filtered.RemoveIf(func(el AttributeValue) bool { pos++ return pos%3 == 0 }) diff --git a/model/pdata/generated_log_test.go b/model/pdata/generated_log_test.go index 4819a205759..7b4c8a3e5d2 100644 --- a/model/pdata/generated_log_test.go +++ b/model/pdata/generated_log_test.go @@ -120,7 +120,7 @@ func TestResourceLogsSlice_MoveAndAppendTo(t *testing.T) { func TestResourceLogsSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewResourceLogsSlice() - emptySlice.RemoveIf(func (el ResourceLogs) bool { + emptySlice.RemoveIf(func(el ResourceLogs) bool { t.Fail() return false }) @@ -128,14 +128,13 @@ func TestResourceLogsSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestResourceLogsSlice() pos := 0 - filtered.RemoveIf(func (el ResourceLogs) bool { + filtered.RemoveIf(func(el ResourceLogs) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestResourceLogs_CopyTo(t *testing.T) { ms := NewResourceLogs() generateTestResourceLogs().CopyTo(ms) @@ -251,7 +250,7 @@ func TestInstrumentationLibraryLogsSlice_MoveAndAppendTo(t *testing.T) { func TestInstrumentationLibraryLogsSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewInstrumentationLibraryLogsSlice() - emptySlice.RemoveIf(func (el InstrumentationLibraryLogs) bool { + emptySlice.RemoveIf(func(el InstrumentationLibraryLogs) bool { t.Fail() return false }) @@ -259,14 +258,13 @@ func TestInstrumentationLibraryLogsSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestInstrumentationLibraryLogsSlice() pos := 0 - filtered.RemoveIf(func (el InstrumentationLibraryLogs) bool { + filtered.RemoveIf(func(el InstrumentationLibraryLogs) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestInstrumentationLibraryLogs_CopyTo(t *testing.T) { ms := NewInstrumentationLibraryLogs() generateTestInstrumentationLibraryLogs().CopyTo(ms) @@ -382,7 +380,7 @@ func TestLogSlice_MoveAndAppendTo(t *testing.T) { func TestLogSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewLogSlice() - emptySlice.RemoveIf(func (el LogRecord) bool { + emptySlice.RemoveIf(func(el LogRecord) bool { t.Fail() return false }) @@ -390,14 +388,13 @@ func TestLogSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestLogSlice() pos := 0 - filtered.RemoveIf(func (el LogRecord) bool { + filtered.RemoveIf(func(el LogRecord) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestLogRecord_CopyTo(t *testing.T) { ms := NewLogRecord() generateTestLogRecord().CopyTo(ms) diff --git a/model/pdata/generated_metrics.go b/model/pdata/generated_metrics.go index 715bc1019d1..48e1ca61391 100644 --- a/model/pdata/generated_metrics.go +++ b/model/pdata/generated_metrics.go @@ -563,8 +563,6 @@ func (ms Metric) SetUnit(v string) { (*ms.orig).Unit = v } - - // CopyTo copies all properties from the current struct to the dest. func (ms Metric) CopyTo(dest Metric) { dest.SetName(ms.Name()) @@ -1968,6 +1966,7 @@ func (es IntExemplarSlice) AppendEmpty() IntExemplar { *es.orig = append(*es.orig, otlpmetrics.IntExemplar{}) return es.At(es.Len() - 1) } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es IntExemplarSlice) MoveAndAppendTo(dest IntExemplarSlice) { @@ -2142,6 +2141,7 @@ func (es ExemplarSlice) AppendEmpty() Exemplar { *es.orig = append(*es.orig, otlpmetrics.Exemplar{}) return es.At(es.Len() - 1) } + // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. // The current slice will be cleared. func (es ExemplarSlice) MoveAndAppendTo(dest ExemplarSlice) { diff --git a/model/pdata/generated_metrics_test.go b/model/pdata/generated_metrics_test.go index 16ddc9952a7..225f19e8381 100644 --- a/model/pdata/generated_metrics_test.go +++ b/model/pdata/generated_metrics_test.go @@ -120,7 +120,7 @@ func TestResourceMetricsSlice_MoveAndAppendTo(t *testing.T) { func TestResourceMetricsSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewResourceMetricsSlice() - emptySlice.RemoveIf(func (el ResourceMetrics) bool { + emptySlice.RemoveIf(func(el ResourceMetrics) bool { t.Fail() return false }) @@ -128,14 +128,13 @@ func TestResourceMetricsSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestResourceMetricsSlice() pos := 0 - filtered.RemoveIf(func (el ResourceMetrics) bool { + filtered.RemoveIf(func(el ResourceMetrics) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestResourceMetrics_CopyTo(t *testing.T) { ms := NewResourceMetrics() generateTestResourceMetrics().CopyTo(ms) @@ -251,7 +250,7 @@ func TestInstrumentationLibraryMetricsSlice_MoveAndAppendTo(t *testing.T) { func TestInstrumentationLibraryMetricsSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewInstrumentationLibraryMetricsSlice() - emptySlice.RemoveIf(func (el InstrumentationLibraryMetrics) bool { + emptySlice.RemoveIf(func(el InstrumentationLibraryMetrics) bool { t.Fail() return false }) @@ -259,14 +258,13 @@ func TestInstrumentationLibraryMetricsSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestInstrumentationLibraryMetricsSlice() pos := 0 - filtered.RemoveIf(func (el InstrumentationLibraryMetrics) bool { + filtered.RemoveIf(func(el InstrumentationLibraryMetrics) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestInstrumentationLibraryMetrics_CopyTo(t *testing.T) { ms := NewInstrumentationLibraryMetrics() generateTestInstrumentationLibraryMetrics().CopyTo(ms) @@ -382,7 +380,7 @@ func TestMetricSlice_MoveAndAppendTo(t *testing.T) { func TestMetricSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewMetricSlice() - emptySlice.RemoveIf(func (el Metric) bool { + emptySlice.RemoveIf(func(el Metric) bool { t.Fail() return false }) @@ -390,14 +388,13 @@ func TestMetricSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestMetricSlice() pos := 0 - filtered.RemoveIf(func (el Metric) bool { + filtered.RemoveIf(func(el Metric) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestMetric_CopyTo(t *testing.T) { ms := NewMetric() generateTestMetric().CopyTo(ms) @@ -428,9 +425,6 @@ func TestMetric_Unit(t *testing.T) { assert.EqualValues(t, testValUnit, ms.Unit()) } - - - func TestIntGauge_CopyTo(t *testing.T) { ms := NewIntGauge() generateTestIntGauge().CopyTo(ms) @@ -445,7 +439,6 @@ func TestIntGauge_DataPoints(t *testing.T) { assert.EqualValues(t, testValDataPoints, ms.DataPoints()) } - func TestGauge_CopyTo(t *testing.T) { ms := NewGauge() generateTestGauge().CopyTo(ms) @@ -460,7 +453,6 @@ func TestGauge_DataPoints(t *testing.T) { assert.EqualValues(t, testValDataPoints, ms.DataPoints()) } - func TestIntSum_CopyTo(t *testing.T) { ms := NewIntSum() generateTestIntSum().CopyTo(ms) @@ -491,7 +483,6 @@ func TestIntSum_DataPoints(t *testing.T) { assert.EqualValues(t, testValDataPoints, ms.DataPoints()) } - func TestSum_CopyTo(t *testing.T) { ms := NewSum() generateTestSum().CopyTo(ms) @@ -522,7 +513,6 @@ func TestSum_DataPoints(t *testing.T) { assert.EqualValues(t, testValDataPoints, ms.DataPoints()) } - func TestHistogram_CopyTo(t *testing.T) { ms := NewHistogram() generateTestHistogram().CopyTo(ms) @@ -545,7 +535,6 @@ func TestHistogram_DataPoints(t *testing.T) { assert.EqualValues(t, testValDataPoints, ms.DataPoints()) } - func TestSummary_CopyTo(t *testing.T) { ms := NewSummary() generateTestSummary().CopyTo(ms) @@ -655,7 +644,7 @@ func TestIntDataPointSlice_MoveAndAppendTo(t *testing.T) { func TestIntDataPointSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewIntDataPointSlice() - emptySlice.RemoveIf(func (el IntDataPoint) bool { + emptySlice.RemoveIf(func(el IntDataPoint) bool { t.Fail() return false }) @@ -663,14 +652,13 @@ func TestIntDataPointSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestIntDataPointSlice() pos := 0 - filtered.RemoveIf(func (el IntDataPoint) bool { + filtered.RemoveIf(func(el IntDataPoint) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestIntDataPoint_CopyTo(t *testing.T) { ms := NewIntDataPoint() generateTestIntDataPoint().CopyTo(ms) @@ -812,7 +800,7 @@ func TestNumberDataPointSlice_MoveAndAppendTo(t *testing.T) { func TestNumberDataPointSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewNumberDataPointSlice() - emptySlice.RemoveIf(func (el NumberDataPoint) bool { + emptySlice.RemoveIf(func(el NumberDataPoint) bool { t.Fail() return false }) @@ -820,14 +808,13 @@ func TestNumberDataPointSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestNumberDataPointSlice() pos := 0 - filtered.RemoveIf(func (el NumberDataPoint) bool { + filtered.RemoveIf(func(el NumberDataPoint) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestNumberDataPoint_CopyTo(t *testing.T) { ms := NewNumberDataPoint() generateTestNumberDataPoint().CopyTo(ms) @@ -969,7 +956,7 @@ func TestHistogramDataPointSlice_MoveAndAppendTo(t *testing.T) { func TestHistogramDataPointSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewHistogramDataPointSlice() - emptySlice.RemoveIf(func (el HistogramDataPoint) bool { + emptySlice.RemoveIf(func(el HistogramDataPoint) bool { t.Fail() return false }) @@ -977,14 +964,13 @@ func TestHistogramDataPointSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestHistogramDataPointSlice() pos := 0 - filtered.RemoveIf(func (el HistogramDataPoint) bool { + filtered.RemoveIf(func(el HistogramDataPoint) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestHistogramDataPoint_CopyTo(t *testing.T) { ms := NewHistogramDataPoint() generateTestHistogramDataPoint().CopyTo(ms) @@ -1150,7 +1136,7 @@ func TestSummaryDataPointSlice_MoveAndAppendTo(t *testing.T) { func TestSummaryDataPointSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewSummaryDataPointSlice() - emptySlice.RemoveIf(func (el SummaryDataPoint) bool { + emptySlice.RemoveIf(func(el SummaryDataPoint) bool { t.Fail() return false }) @@ -1158,14 +1144,13 @@ func TestSummaryDataPointSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestSummaryDataPointSlice() pos := 0 - filtered.RemoveIf(func (el SummaryDataPoint) bool { + filtered.RemoveIf(func(el SummaryDataPoint) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestSummaryDataPoint_CopyTo(t *testing.T) { ms := NewSummaryDataPoint() generateTestSummaryDataPoint().CopyTo(ms) @@ -1315,7 +1300,7 @@ func TestValueAtQuantileSlice_MoveAndAppendTo(t *testing.T) { func TestValueAtQuantileSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewValueAtQuantileSlice() - emptySlice.RemoveIf(func (el ValueAtQuantile) bool { + emptySlice.RemoveIf(func(el ValueAtQuantile) bool { t.Fail() return false }) @@ -1323,14 +1308,13 @@ func TestValueAtQuantileSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestValueAtQuantileSlice() pos := 0 - filtered.RemoveIf(func (el ValueAtQuantile) bool { + filtered.RemoveIf(func(el ValueAtQuantile) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestValueAtQuantile_CopyTo(t *testing.T) { ms := NewValueAtQuantile() generateTestValueAtQuantile().CopyTo(ms) @@ -1439,7 +1423,7 @@ func TestIntExemplarSlice_MoveAndAppendTo(t *testing.T) { func TestIntExemplarSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewIntExemplarSlice() - emptySlice.RemoveIf(func (el IntExemplar) bool { + emptySlice.RemoveIf(func(el IntExemplar) bool { t.Fail() return false }) @@ -1447,14 +1431,13 @@ func TestIntExemplarSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestIntExemplarSlice() pos := 0 - filtered.RemoveIf(func (el IntExemplar) bool { + filtered.RemoveIf(func(el IntExemplar) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestIntExemplar_CopyTo(t *testing.T) { ms := NewIntExemplar() generateTestIntExemplar().CopyTo(ms) @@ -1571,7 +1554,7 @@ func TestExemplarSlice_MoveAndAppendTo(t *testing.T) { func TestExemplarSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewExemplarSlice() - emptySlice.RemoveIf(func (el Exemplar) bool { + emptySlice.RemoveIf(func(el Exemplar) bool { t.Fail() return false }) @@ -1579,14 +1562,13 @@ func TestExemplarSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestExemplarSlice() pos := 0 - filtered.RemoveIf(func (el Exemplar) bool { + filtered.RemoveIf(func(el Exemplar) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestExemplar_CopyTo(t *testing.T) { ms := NewExemplar() generateTestExemplar().CopyTo(ms) diff --git a/model/pdata/generated_resource_test.go b/model/pdata/generated_resource_test.go index b96b74e5fa7..cff3992e35f 100644 --- a/model/pdata/generated_resource_test.go +++ b/model/pdata/generated_resource_test.go @@ -23,7 +23,6 @@ import ( "github.com/stretchr/testify/assert" ) - func TestResource_CopyTo(t *testing.T) { ms := NewResource() generateTestResource().CopyTo(ms) diff --git a/model/pdata/generated_trace_test.go b/model/pdata/generated_trace_test.go index 8f14e7bbcbe..b7de1f73721 100644 --- a/model/pdata/generated_trace_test.go +++ b/model/pdata/generated_trace_test.go @@ -120,7 +120,7 @@ func TestResourceSpansSlice_MoveAndAppendTo(t *testing.T) { func TestResourceSpansSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewResourceSpansSlice() - emptySlice.RemoveIf(func (el ResourceSpans) bool { + emptySlice.RemoveIf(func(el ResourceSpans) bool { t.Fail() return false }) @@ -128,14 +128,13 @@ func TestResourceSpansSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestResourceSpansSlice() pos := 0 - filtered.RemoveIf(func (el ResourceSpans) bool { + filtered.RemoveIf(func(el ResourceSpans) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestResourceSpans_CopyTo(t *testing.T) { ms := NewResourceSpans() generateTestResourceSpans().CopyTo(ms) @@ -251,7 +250,7 @@ func TestInstrumentationLibrarySpansSlice_MoveAndAppendTo(t *testing.T) { func TestInstrumentationLibrarySpansSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewInstrumentationLibrarySpansSlice() - emptySlice.RemoveIf(func (el InstrumentationLibrarySpans) bool { + emptySlice.RemoveIf(func(el InstrumentationLibrarySpans) bool { t.Fail() return false }) @@ -259,14 +258,13 @@ func TestInstrumentationLibrarySpansSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestInstrumentationLibrarySpansSlice() pos := 0 - filtered.RemoveIf(func (el InstrumentationLibrarySpans) bool { + filtered.RemoveIf(func(el InstrumentationLibrarySpans) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestInstrumentationLibrarySpans_CopyTo(t *testing.T) { ms := NewInstrumentationLibrarySpans() generateTestInstrumentationLibrarySpans().CopyTo(ms) @@ -382,7 +380,7 @@ func TestSpanSlice_MoveAndAppendTo(t *testing.T) { func TestSpanSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewSpanSlice() - emptySlice.RemoveIf(func (el Span) bool { + emptySlice.RemoveIf(func(el Span) bool { t.Fail() return false }) @@ -390,14 +388,13 @@ func TestSpanSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestSpanSlice() pos := 0 - filtered.RemoveIf(func (el Span) bool { + filtered.RemoveIf(func(el Span) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestSpan_CopyTo(t *testing.T) { ms := NewSpan() generateTestSpan().CopyTo(ms) @@ -617,7 +614,7 @@ func TestSpanEventSlice_MoveAndAppendTo(t *testing.T) { func TestSpanEventSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewSpanEventSlice() - emptySlice.RemoveIf(func (el SpanEvent) bool { + emptySlice.RemoveIf(func(el SpanEvent) bool { t.Fail() return false }) @@ -625,14 +622,13 @@ func TestSpanEventSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestSpanEventSlice() pos := 0 - filtered.RemoveIf(func (el SpanEvent) bool { + filtered.RemoveIf(func(el SpanEvent) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestSpanEvent_CopyTo(t *testing.T) { ms := NewSpanEvent() generateTestSpanEvent().CopyTo(ms) @@ -766,7 +762,7 @@ func TestSpanLinkSlice_MoveAndAppendTo(t *testing.T) { func TestSpanLinkSlice_RemoveIf(t *testing.T) { // Test RemoveIf on empty slice emptySlice := NewSpanLinkSlice() - emptySlice.RemoveIf(func (el SpanLink) bool { + emptySlice.RemoveIf(func(el SpanLink) bool { t.Fail() return false }) @@ -774,14 +770,13 @@ func TestSpanLinkSlice_RemoveIf(t *testing.T) { // Test RemoveIf filtered := generateTestSpanLinkSlice() pos := 0 - filtered.RemoveIf(func (el SpanLink) bool { + filtered.RemoveIf(func(el SpanLink) bool { pos++ return pos%3 == 0 }) assert.Equal(t, 5, filtered.Len()) } - func TestSpanLink_CopyTo(t *testing.T) { ms := NewSpanLink() generateTestSpanLink().CopyTo(ms) @@ -828,7 +823,6 @@ func TestSpanLink_DroppedAttributesCount(t *testing.T) { assert.EqualValues(t, testValDroppedAttributesCount, ms.DroppedAttributesCount()) } - func TestSpanStatus_CopyTo(t *testing.T) { ms := NewSpanStatus() generateTestSpanStatus().CopyTo(ms)