@@ -9,12 +9,15 @@ import (
9
9
"bytes"
10
10
"fmt"
11
11
"io"
12
+ "math"
12
13
"strconv"
13
14
"strings"
14
15
"sync"
15
16
"sync/atomic"
16
17
"testing"
17
18
19
+ "github.com/DataDog/dd-trace-go/v2/internal/globalconfig"
20
+ "github.com/DataDog/dd-trace-go/v2/internal/version"
18
21
"github.com/stretchr/testify/assert"
19
22
"github.com/tinylib/msgp/msgp"
20
23
)
@@ -82,17 +85,18 @@ func TestPayloadV04Decode(t *testing.T) {
82
85
func TestPayloadV1Decode (t * testing.T ) {
83
86
for _ , n := range []int {10 , 1 << 10 } {
84
87
t .Run (strconv .Itoa (n ), func (t * testing.T ) {
85
- assert := assert .New (t )
86
- p := newPayloadV1 ()
87
-
88
- p .containerID = "containerID"
89
- p .languageName = "languageName"
90
- p .languageVersion = "languageVersion"
91
- p .tracerVersion = "tracerVersion"
92
- p .runtimeID = "runtimeID"
93
- p .env = "env"
94
- p .hostname = "hostname"
95
- p .appVersion = "appVersion"
88
+ var (
89
+ assert = assert .New (t )
90
+ p = newPayloadV1 ()
91
+ )
92
+ p .SetContainerID ("containerID" )
93
+ p .SetLanguageName ("go" )
94
+ p .SetLanguageVersion ("1.25" )
95
+ p .SetTracerVersion (version .Tag )
96
+ p .SetRuntimeID (globalconfig .RuntimeID ())
97
+ p .SetEnv ("test" )
98
+ p .SetHostname ("hostname" )
99
+ p .SetAppVersion ("appVersion" )
96
100
97
101
for i := 0 ; i < n ; i ++ {
98
102
_ , _ = p .push (newSpanList (i % 5 + 1 ))
@@ -102,17 +106,56 @@ func TestPayloadV1Decode(t *testing.T) {
102
106
assert .NoError (err )
103
107
104
108
got := newPayloadV1 ()
105
- _ , err = got .Decode (encoded )
109
+ buf := bytes .NewBuffer (encoded )
110
+ _ , err = buf .WriteTo (got )
106
111
assert .NoError (err )
107
112
108
- assert .Equal (p .containerID , got .containerID )
109
- assert .Equal (p .languageName , got .languageName )
110
- assert .Equal (p .languageVersion , got .languageVersion )
111
- assert .Equal (p .tracerVersion , got .tracerVersion )
112
- assert .Equal (p .runtimeID , got .runtimeID )
113
- assert .Equal (p .env , got .env )
114
- assert .Equal (p .hostname , got .hostname )
115
- assert .Equal (p .appVersion , got .appVersion )
113
+ o , err := got .hydrate ()
114
+ assert .NoError (err )
115
+ assert .Empty (o )
116
+ assert .Equal (p .strings .strings , []string {
117
+ "" ,
118
+ "containerID" ,
119
+ "go" ,
120
+ "1.25" ,
121
+ version .Tag ,
122
+ globalconfig .RuntimeID (),
123
+ "test" ,
124
+ "hostname" ,
125
+ "appVersion" ,
126
+ })
127
+ assert .Equal (p .ContainerID (), got .ContainerID ())
128
+ assert .Equal (p .LanguageName (), got .LanguageName ())
129
+ assert .Equal (p .LanguageVersion (), got .LanguageVersion ())
130
+ assert .Equal (p .TracerVersion (), got .TracerVersion ())
131
+ assert .Equal (p .RuntimeID (), got .RuntimeID ())
132
+ assert .Equal (p .Env (), got .Env ())
133
+ assert .Equal (p .Hostname (), got .Hostname ())
134
+ assert .Equal (p .AppVersion (), got .AppVersion ())
135
+ })
136
+ }
137
+ }
138
+
139
+ func TestPayloadV1UpdateHeader (t * testing.T ) {
140
+ testCases := []uint32 { // Number of items
141
+ 15 ,
142
+ math .MaxUint16 ,
143
+ math .MaxUint32 ,
144
+ }
145
+ for _ , tc := range testCases {
146
+ t .Run (fmt .Sprintf ("n=%d" , tc ), func (t * testing.T ) {
147
+ var (
148
+ p = payloadV1 {
149
+ fields : tc ,
150
+ header : make ([]byte , 8 ),
151
+ }
152
+ expected []byte
153
+ )
154
+ expected = msgp .AppendMapHeader (expected , tc )
155
+ p .updateHeader ()
156
+ if got := p .header [p .off :]; ! bytes .Equal (expected , got ) {
157
+ t .Fatalf ("expected %+v, got %+v" , expected , got )
158
+ }
116
159
})
117
160
}
118
161
}
0 commit comments