-
Notifications
You must be signed in to change notification settings - Fork 2
/
traceid_test.go
94 lines (81 loc) · 2.06 KB
/
traceid_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package klogga
import (
"encoding/json"
"github.com/stretchr/testify/require"
"testing"
)
func TestCreateParseTraceID(t *testing.T) {
id := NewTraceID()
res, err := TraceIDFromString(id.String())
require.NoError(t, err)
require.Equal(t, id, res)
}
func TestJsonMarshalTraceID(t *testing.T) {
id := NewTraceID()
jsonStr, err := json.Marshal(&id)
require.NoError(t, err)
var unmarshalledID TraceID
err = json.Unmarshal(jsonStr, &unmarshalledID)
require.NoError(t, err)
require.Equal(t, id, unmarshalledID)
}
func TestJsonMarshalTraceIDinStruct(t *testing.T) {
id := NewTraceID()
type St struct {
ID TraceID
Some string
}
val := St{id, "lala"}
jsonStr, err := json.Marshal(&val)
require.NoError(t, err)
var unmarshalledID St
err = json.Unmarshal(jsonStr, &unmarshalledID)
require.NoError(t, err)
require.Equal(t, id, unmarshalledID.ID)
t.Log("json:", string(jsonStr))
}
func TestCreateParseSpanID(t *testing.T) {
id := NewSpanID()
res, err := SpanIDFromString(id.String())
require.NoError(t, err)
require.Equal(t, id, res)
}
func TestJsonMarshalSpanID(t *testing.T) {
id := NewSpanID()
jsonStr, err := json.Marshal(&id)
require.NoError(t, err)
var unmarshalledID SpanID
err = json.Unmarshal(jsonStr, &unmarshalledID)
require.NoError(t, err)
require.Equal(t, id, unmarshalledID)
}
func TestJsonMarshalSpanIDinStruct(t *testing.T) {
id := NewSpanID()
type St struct {
Some string
ID SpanID
}
val := St{"lala", id}
jsonStr, err := json.Marshal(&val)
require.NoError(t, err)
var unmarshalledID St
err = json.Unmarshal(jsonStr, &unmarshalledID)
require.NoError(t, err)
require.Equal(t, id, unmarshalledID.ID)
}
func TestJsonMarshalIDsInStruct(t *testing.T) {
idT, idS := TraceID{}, SpanID{}
type St struct {
ID SpanID
TraceID TraceID
}
val := St{idS, idT}
jsonStr, err := json.Marshal(&val)
require.NoError(t, err)
var unmarshalledID St
err = json.Unmarshal(jsonStr, &unmarshalledID)
require.NoError(t, err)
require.Equal(t, idS, unmarshalledID.ID)
require.Equal(t, idT, unmarshalledID.TraceID)
t.Log("json:", string(jsonStr))
}