diff --git a/input/elasticapm/internal/modeldecoder/modeldecodertest/populator.go b/input/elasticapm/internal/modeldecoder/modeldecodertest/populator.go index 8c1054f4..f913078b 100644 --- a/input/elasticapm/internal/modeldecoder/modeldecodertest/populator.go +++ b/input/elasticapm/internal/modeldecoder/modeldecodertest/populator.go @@ -27,6 +27,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "google.golang.org/protobuf/types/known/timestamppb" "github.com/elastic/apm-data/input/elasticapm/internal/modeldecoder/nullable" "github.com/elastic/apm-data/model" @@ -131,7 +132,7 @@ func SetStructValues(in interface{}, values *Values, opts ...SetStructValuesOpti switch fKind := f.Kind(); fKind { case reflect.String: fieldVal = reflect.ValueOf(values.Str) - case reflect.Int, reflect.Int64: + case reflect.Int, reflect.Int32, reflect.Int64: fieldVal = reflect.ValueOf(values.Int).Convert(f.Type()) case reflect.Float64: fieldVal = reflect.ValueOf(values.Float).Convert(f.Type()) @@ -265,10 +266,6 @@ func SetZeroStructValue(i interface{}, callback func(string)) { // that values are equal to expected values func AssertStructValues(t *testing.T, i interface{}, isException func(string) bool, values *Values) { - if true { - // TODO FIX no op protobuf support - return - } IterateStruct(i, func(f reflect.Value, key string) { if isException(key) { return @@ -308,7 +305,7 @@ func AssertStructValues(t *testing.T, i interface{}, isException func(string) bo case *int: newVal = &values.Int case int32: - newVal = values.Int + newVal = int32(values.Int) case uint32: newVal = uint32(values.Int) case *uint32: @@ -327,8 +324,8 @@ func AssertStructValues(t *testing.T, i interface{}, isException func(string) bo newVal = &values.Bool case http.Header: newVal = values.HTTPHeader - case time.Time: - newVal = values.Time + case *timestamppb.Timestamp: + newVal = timestamppb.New(values.Time) case time.Duration: newVal = values.Duration case modelpb.MetricType: diff --git a/input/elasticapm/internal/modeldecoder/rumv3/error_test.go b/input/elasticapm/internal/modeldecoder/rumv3/error_test.go index 573b00bc..5a3bd21f 100644 --- a/input/elasticapm/internal/modeldecoder/rumv3/error_test.go +++ b/input/elasticapm/internal/modeldecoder/rumv3/error_test.go @@ -23,8 +23,10 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/testing/protocmp" "github.com/elastic/apm-data/input/elasticapm/internal/decoder" "github.com/elastic/apm-data/input/elasticapm/internal/modeldecoder" @@ -54,9 +56,14 @@ func TestDecodeNestedError(t *testing.T) { require.NoError(t, DecodeNestedError(dec, &input, &batch)) require.Len(t, batch, 1) require.NotNil(t, batch[0].Error) - defaultValues := modeldecodertest.DefaultValues() - defaultValues.Update(time.Unix(1599996822, 281000000).UTC()) - modeldecodertest.AssertStructValues(t, &batch[0], metadataExceptions(), defaultValues) + assert.Equal(t, time.Unix(1599996822, 281000000).UTC(), batch[0].Timestamp.AsTime()) + assert.Empty(t, cmp.Diff(&modelpb.Error{ + Id: "a-b-c", + Log: &modelpb.ErrorLog{ + Message: "abc", + LoggerName: "default", + }, + }, batch[0].Error, protocmp.Transform())) // if no timestamp is provided, leave base event timestamp unmodified input = modeldecoder.Input{Base: eventBase} diff --git a/input/elasticapm/internal/modeldecoder/rumv3/transaction_test.go b/input/elasticapm/internal/modeldecoder/rumv3/transaction_test.go index 3224922c..0eee3daf 100644 --- a/input/elasticapm/internal/modeldecoder/rumv3/transaction_test.go +++ b/input/elasticapm/internal/modeldecoder/rumv3/transaction_test.go @@ -87,14 +87,6 @@ func TestDecodeNestedTransaction(t *testing.T) { assert.Equal(t, "1", batch[2].Trace.Id) assert.Equal(t, "100", batch[2].Parent.Id) - for _, event := range batch { - modeldecodertest.AssertStructValues( - t, &event, - metadataExceptions("Timestamp"), // timestamp checked above - modeldecodertest.DefaultValues(), - ) - } - err := DecodeNestedTransaction(decoder.NewJSONDecoder(strings.NewReader(`malformed`)), &input, &batch) require.Error(t, err) assert.Contains(t, err.Error(), "decode") diff --git a/input/elasticapm/internal/modeldecoder/v2/error_test.go b/input/elasticapm/internal/modeldecoder/v2/error_test.go index 65a11282..9ebbf048 100644 --- a/input/elasticapm/internal/modeldecoder/v2/error_test.go +++ b/input/elasticapm/internal/modeldecoder/v2/error_test.go @@ -24,8 +24,10 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/testing/protocmp" "github.com/elastic/apm-data/input/elasticapm/internal/decoder" "github.com/elastic/apm-data/input/elasticapm/internal/modeldecoder" @@ -56,9 +58,11 @@ func TestDecodeNestedError(t *testing.T) { require.NoError(t, DecodeNestedError(dec, &input, &batch)) require.Len(t, batch, 1) require.NotNil(t, batch[0].Error) - - defaultVal.Update(time.Unix(1599996822, 281000000).UTC()) - modeldecodertest.AssertStructValues(t, &batch[0], isMetadataException, defaultVal) + assert.Equal(t, time.Unix(1599996822, 281000000).UTC(), batch[0].Timestamp.AsTime()) + assert.Empty(t, cmp.Diff(&modelpb.Error{ + Id: "a-b-c", + Log: &modelpb.ErrorLog{Message: "abc"}, + }, batch[0].Error, protocmp.Transform())) str = `{"error":{"id":"a-b-c","log":{"message":"abc"},"context":{"experimental":"exp"}}}` dec = decoder.NewJSONDecoder(strings.NewReader(str)) diff --git a/input/elasticapm/internal/modeldecoder/v2/metricset_test.go b/input/elasticapm/internal/modeldecoder/v2/metricset_test.go index 9e19b28d..7728e9fa 100644 --- a/input/elasticapm/internal/modeldecoder/v2/metricset_test.go +++ b/input/elasticapm/internal/modeldecoder/v2/metricset_test.go @@ -58,9 +58,14 @@ func TestDecodeNestedMetricset(t *testing.T) { require.NoError(t, DecodeNestedMetricset(dec, &input, &batch)) require.Len(t, batch, 1) require.NotNil(t, batch[0].Metricset) - assert.Equal(t, []*modelpb.MetricsetSample{{Name: "a.b", Value: 2048}}, batch[0].Metricset.Samples) - defaultVal.Update(time.Unix(1599996822, 281000000).UTC()) - modeldecodertest.AssertStructValues(t, &batch[0], isMetadataException, defaultVal) + assert.Equal(t, time.Unix(1599996822, 281000000).UTC(), batch[0].Timestamp.AsTime()) + assert.Empty(t, cmp.Diff(&modelpb.Metricset{ + Name: "app", + Samples: []*modelpb.MetricsetSample{{ + Name: "a.b", + Value: 2048, + }}, + }, batch[0].Metricset, protocmp.Transform())) // invalid type err := DecodeNestedMetricset(decoder.NewJSONDecoder(strings.NewReader(`malformed`)), &input, &batch) diff --git a/input/elasticapm/internal/modeldecoder/v2/span_test.go b/input/elasticapm/internal/modeldecoder/v2/span_test.go index 57ae5454..adf47d19 100644 --- a/input/elasticapm/internal/modeldecoder/v2/span_test.go +++ b/input/elasticapm/internal/modeldecoder/v2/span_test.go @@ -25,9 +25,11 @@ import ( "testing" "time" + "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" + "google.golang.org/protobuf/testing/protocmp" "github.com/elastic/apm-data/input/elasticapm/internal/decoder" "github.com/elastic/apm-data/input/elasticapm/internal/modeldecoder" @@ -57,8 +59,16 @@ func TestDecodeNestedSpan(t *testing.T) { require.NoError(t, DecodeNestedSpan(dec, &input, &batch)) require.Len(t, batch, 1) require.NotNil(t, batch[0].Span) - defaultVal.Update(time.Time{}.Add(143 * time.Millisecond)) - modeldecodertest.AssertStructValues(t, &batch[0], isMetadataException, defaultVal) + assert.Equal(t, time.Time{}.Add(143*time.Millisecond), batch[0].Timestamp.AsTime()) + assert.Equal(t, 100*time.Millisecond, batch[0].Event.Duration.AsDuration()) + assert.Equal(t, &modelpb.Parent{Id: "parent-123"}, batch[0].Parent, protocmp.Transform()) + assert.Equal(t, &modelpb.Trace{Id: "trace-ab"}, batch[0].Trace, protocmp.Transform()) + assert.Empty(t, cmp.Diff(&modelpb.Span{ + Name: "s", + Type: "db", + Id: "a-b-c", + RepresentativeCount: 1, + }, batch[0].Span, protocmp.Transform())) err := DecodeNestedSpan(decoder.NewJSONDecoder(strings.NewReader(`malformed`)), &input, &batch) require.Error(t, err)