mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
* rename batches property of Trace to ResourceSpans to be OTEL compatible * added test to assert that the response hasn't change * update test data * fix unmarshall test * changelog * fix e2e * try to fix flaky test * create helper functions to marshal and unmarshal traces to OTEL compatible schema * added better documentation
39 lines
820 B
Go
39 lines
820 B
Go
package tempopb
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
|
|
v1 "github.com/grafana/tempo/pkg/tempopb/trace/v1"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMarshalToJSONV1(t *testing.T) {
|
|
trace := &Trace{
|
|
ResourceSpans: make([]*v1.ResourceSpans, 0),
|
|
}
|
|
jsonBytes, err := MarshalToJSONV1(trace)
|
|
|
|
assert.NoError(t, err)
|
|
assert.True(t, strings.Contains(string(jsonBytes), "batches"))
|
|
|
|
trace2 := &Trace{}
|
|
err = UnmarshalFromJSONV1(jsonBytes, trace2)
|
|
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, trace, trace2)
|
|
}
|
|
|
|
func TestUnMarshalToJSONV1(t *testing.T) {
|
|
file, _ := os.Open("trace.json")
|
|
defer file.Close()
|
|
trace := &Trace{}
|
|
content, _ := io.ReadAll(file)
|
|
err := UnmarshalFromJSONV1(content, trace)
|
|
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, "my.library", trace.ResourceSpans[0].ScopeSpans[0].Scope.Name)
|
|
}
|