mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
Remove the complication about internal/public for all funcs that only need origin. Also improves significant testing. This simplified a lot the fields (no more isCommon/isBaseCommon/etc.) Signed-off-by: Bogdan Drutu <[email protected]>
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package pprofileotlp
|
|
|
|
import (
|
|
stdjson "encoding/json"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var (
|
|
_ stdjson.Unmarshaler = ExportResponse{}
|
|
_ stdjson.Marshaler = ExportResponse{}
|
|
)
|
|
|
|
func TestExportResponseJSON(t *testing.T) {
|
|
jsonStr := `{"partialSuccess": {"rejectedProfiles":"1", "errorMessage":"nothing"}}`
|
|
val := NewExportResponse()
|
|
require.NoError(t, val.UnmarshalJSON([]byte(jsonStr)))
|
|
expected := NewExportResponse()
|
|
expected.PartialSuccess().SetRejectedProfiles(1)
|
|
expected.PartialSuccess().SetErrorMessage("nothing")
|
|
assert.Equal(t, expected, val)
|
|
buf, err := val.MarshalJSON()
|
|
require.NoError(t, err)
|
|
assert.JSONEq(t, jsonStr, string(buf))
|
|
}
|
|
|
|
func TestUnmarshalJSONExportResponse(t *testing.T) {
|
|
jsonStr := `{"extra":"", "partialSuccess": {"extra":""}}`
|
|
val := NewExportResponse()
|
|
require.NoError(t, val.UnmarshalJSON([]byte(jsonStr)))
|
|
assert.Equal(t, NewExportResponse(), val)
|
|
}
|