@@ -9,12 +9,15 @@ import (
99	"bytes" 
1010	"fmt" 
1111	"io" 
12+ 	"math" 
1213	"strconv" 
1314	"strings" 
1415	"sync" 
1516	"sync/atomic" 
1617	"testing" 
1718
19+ 	"github.com/DataDog/dd-trace-go/v2/internal/globalconfig" 
20+ 	"github.com/DataDog/dd-trace-go/v2/internal/version" 
1821	"github.com/stretchr/testify/assert" 
1922	"github.com/tinylib/msgp/msgp" 
2023)
@@ -82,17 +85,18 @@ func TestPayloadV04Decode(t *testing.T) {
8285func  TestPayloadV1Decode (t  * testing.T ) {
8386	for  _ , n  :=  range  []int {10 , 1  <<  10 } {
8487		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" )
96100
97101			for  i  :=  0 ; i  <  n ; i ++  {
98102				_ , _  =  p .push (newSpanList (i % 5  +  1 ))
@@ -102,17 +106,57 @@ func TestPayloadV1Decode(t *testing.T) {
102106			assert .NoError (err )
103107
104108			got  :=  newPayloadV1 ()
105- 			_ , err  =  got .Decode (encoded )
109+ 			buf  :=  bytes .NewBuffer (encoded )
110+ 			_ , err  =  buf .WriteTo (got )
106111			assert .NoError (err )
107112
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 (got .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+ 			assert .Equal (p .fields , got .fields )
136+ 		})
137+ 	}
138+ }
139+ 
140+ func  TestPayloadV1UpdateHeader (t  * testing.T ) {
141+ 	testCases  :=  []uint32 { // Number of items 
142+ 		15 ,
143+ 		math .MaxUint16 ,
144+ 		math .MaxUint32 ,
145+ 	}
146+ 	for  _ , tc  :=  range  testCases  {
147+ 		t .Run (fmt .Sprintf ("n=%d" , tc ), func (t  * testing.T ) {
148+ 			var  (
149+ 				p  =  payloadV1 {
150+ 					fields : tc ,
151+ 					header : make ([]byte , 8 ),
152+ 				}
153+ 				expected  []byte 
154+ 			)
155+ 			expected  =  msgp .AppendMapHeader (expected , tc )
156+ 			p .updateHeader ()
157+ 			if  got  :=  p .header [p .off :]; ! bytes .Equal (expected , got ) {
158+ 				t .Fatalf ("expected %+v, got %+v" , expected , got )
159+ 			}
116160		})
117161	}
118162}
0 commit comments