| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package pprofile // import "go.opentelemetry.io/collector/pdata/pprofile" |
| 5 |
|
| 6 |
import ( |
| 7 |
"bytes" |
| 8 |
"testing" |
| 9 |
|
| 10 |
"github.com/stretchr/testify/require" |
| 11 |
) |
| 12 |
|
| 13 |
var unexpectedBytes = "expected the same bytes from unmarshaling and marshaling." |
| 14 |
|
| 15 |
func FuzzUnmarshalProfiles(f *testing.F) { |
| 16 |
f.Fuzz(func(t *testing.T, data []byte) { |
| 17 |
u1 := &JSONUnmarshaler{} |
| 18 |
ld1, err := u1.UnmarshalProfiles(data) |
| 19 |
if err != nil { |
| 20 |
return |
| 21 |
} |
| 22 |
m1 := &JSONMarshaler{} |
| 23 |
b1, err := m1.MarshalProfiles(ld1) |
| 24 |
require.NoError(t, err, "failed to marshal valid struct") |
| 25 |
|
| 26 |
u2 := &JSONUnmarshaler{} |
| 27 |
ld2, err := u2.UnmarshalProfiles(b1) |
| 28 |
require.NoError(t, err, "failed to unmarshal valid bytes") |
| 29 |
m2 := &JSONMarshaler{} |
| 30 |
b2, err := m2.MarshalProfiles(ld2) |
| 31 |
require.NoError(t, err, "failed to marshal valid struct") |
| 32 |
|
| 33 |
require.True(t, bytes.Equal(b1, b2), "%s. \nexpected %d but got %d\n", unexpectedBytes, b1, b2) |
| 34 |
}) |
| 35 |
} |