Files
Matthieu MORELandGitHub 1fbdd09ea9 [chore]: use testify instead of testing.Fatal or testing.Error (#11896)
### Description

* uses testify instead of testing.Fatal or testing.Error in processor

Signed-off-by: Matthieu MOREL <[email protected]>
2024-12-16 23:15:33 +00:00

58 lines
1.6 KiB
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package ptrace // import "go.opentelemetry.io/collector/pdata/ptrace"
import (
"bytes"
"testing"
"github.com/stretchr/testify/require"
)
var unexpectedBytes = "expected the same bytes from unmarshaling and marshaling."
func FuzzUnmarshalJSONTraces(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
u1 := &JSONUnmarshaler{}
ld1, err := u1.UnmarshalTraces(data)
if err != nil {
return
}
m1 := &JSONMarshaler{}
b1, err := m1.MarshalTraces(ld1)
require.NoError(t, err, "failed to marshal valid struct")
u2 := &JSONUnmarshaler{}
ld2, err := u2.UnmarshalTraces(b1)
require.NoError(t, err, "failed to unmarshal valid bytes")
m2 := &JSONMarshaler{}
b2, err := m2.MarshalTraces(ld2)
require.NoError(t, err, "failed to marshal valid struct")
require.True(t, bytes.Equal(b1, b2), "%s. \nexpected %d but got %d\n", unexpectedBytes, b1, b2)
})
}
func FuzzUnmarshalPBTraces(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
u1 := &ProtoUnmarshaler{}
ld1, err := u1.UnmarshalTraces(data)
if err != nil {
return
}
m1 := &ProtoMarshaler{}
b1, err := m1.MarshalTraces(ld1)
require.NoError(t, err, "failed to marshal valid struct")
u2 := &ProtoUnmarshaler{}
ld2, err := u2.UnmarshalTraces(b1)
require.NoError(t, err, "failed to unmarshal valid bytes")
m2 := &ProtoMarshaler{}
b2, err := m2.MarshalTraces(ld2)
require.NoError(t, err, "failed to marshal valid struct")
require.True(t, bytes.Equal(b1, b2), "%s. \nexpected %d but got %d\n", unexpectedBytes, b1, b2)
})
}