| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package pprofileotlp |
| 5 |
|
| 6 |
import ( |
| 7 |
stdjson "encoding/json" |
| 8 |
"testing" |
| 9 |
|
| 10 |
"github.com/stretchr/testify/assert" |
| 11 |
"github.com/stretchr/testify/require" |
| 12 |
) |
| 13 |
|
| 14 |
var ( |
| 15 |
_ stdjson.Unmarshaler = ExportResponse{} |
| 16 |
_ stdjson.Marshaler = ExportResponse{} |
| 17 |
) |
| 18 |
|
| 19 |
func TestExportResponseJSON(t *testing.T) { |
| 20 |
jsonStr := `{"partialSuccess": {"rejectedProfiles":"1", "errorMessage":"nothing"}}` |
| 21 |
val := NewExportResponse() |
| 22 |
require.NoError(t, val.UnmarshalJSON([]byte(jsonStr))) |
| 23 |
expected := NewExportResponse() |
| 24 |
expected.PartialSuccess().SetRejectedProfiles(1) |
| 25 |
expected.PartialSuccess().SetErrorMessage("nothing") |
| 26 |
assert.Equal(t, expected, val) |
| 27 |
buf, err := val.MarshalJSON() |
| 28 |
require.NoError(t, err) |
| 29 |
assert.JSONEq(t, jsonStr, string(buf)) |
| 30 |
} |
| 31 |
|
| 32 |
func TestUnmarshalJSONExportResponse(t *testing.T) { |
| 33 |
jsonStr := `{"extra":"", "partialSuccess": {"extra":""}}` |
| 34 |
val := NewExportResponse() |
| 35 |
require.NoError(t, val.UnmarshalJSON([]byte(jsonStr))) |
| 36 |
assert.Equal(t, NewExportResponse(), val) |
| 37 |
} |