mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description - This PR fixes the helpers for AnyValue by changing the API to accept `pcommon.Value`. Since `otlpcommon.AnyValue` is an internal type, the current helpers are not useful as a public API. <!-- Issue number if applicable --> #### Link to tracking issue Fixes #13837 (original issue #12826) <!--Describe what testing was performed and which tests were added.--> #### Testing - Updated unit tests --------- Signed-off-by: Mahad Zaryab <[email protected]>
36 lines
901 B
Go
36 lines
901 B
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package xpdata
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var unexpectedBytes = "expected the same bytes from unmarshaling and marshaling."
|
|
|
|
func FuzzUnmarshalJSONValue(f *testing.F) {
|
|
f.Fuzz(func(t *testing.T, data []byte) {
|
|
u1 := &JSONUnmarshaler{}
|
|
ld1, err := u1.UnmarshalValue(data)
|
|
if err != nil {
|
|
return
|
|
}
|
|
m1 := &JSONMarshaler{}
|
|
b1, err := m1.MarshalValue(ld1)
|
|
require.NoError(t, err, "failed to marshal valid struct")
|
|
|
|
u2 := &JSONUnmarshaler{}
|
|
ld2, err := u2.UnmarshalValue(b1)
|
|
require.NoError(t, err, "failed to unmarshal valid bytes")
|
|
m2 := &JSONMarshaler{}
|
|
b2, err := m2.MarshalValue(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)
|
|
})
|
|
}
|