@@ -128,6 +128,55 @@ func TestExtractValidBaggageFromHTTPReq(t *testing.T) {
128128 }
129129}
130130
131+ func TestExtractValidMultipleBaggageHeaders (t * testing.T ) {
132+ prop := propagation .TextMapPropagator (propagation.Baggage {})
133+ tests := []struct {
134+ name string
135+ headers []string
136+ want members
137+ }{
138+ {
139+ name : "non conflicting headers" ,
140+ headers : []string {"key1=val1" , "key2=val2" },
141+ want : members {
142+ {Key : "key1" , Value : "val1" },
143+ {Key : "key2" , Value : "val2" },
144+ },
145+ },
146+ {
147+ name : "conflicting keys, uses last val" ,
148+ headers : []string {"key1=val1" , "key1=val2" },
149+ want : members {
150+ {Key : "key1" , Value : "val2" },
151+ },
152+ },
153+ {
154+ name : "single empty" ,
155+ headers : []string {"" , "key1=val1" },
156+ want : members {
157+ {Key : "key1" , Value : "val1" },
158+ },
159+ },
160+ {
161+ name : "all empty" ,
162+ headers : []string {"" , "" },
163+ want : members {},
164+ },
165+ }
166+
167+ for _ , tt := range tests {
168+ t .Run (tt .name , func (t * testing.T ) {
169+ req , _ := http .NewRequest ("GET" , "http://example.com" , nil )
170+ req .Header ["Baggage" ] = tt .headers
171+
172+ ctx := context .Background ()
173+ ctx = prop .Extract (ctx , propagation .HeaderCarrier (req .Header ))
174+ expected := tt .want .Baggage (t )
175+ assert .Equal (t , expected , baggage .FromContext (ctx ))
176+ })
177+ }
178+ }
179+
131180func TestExtractInvalidDistributedContextFromHTTPReq (t * testing.T ) {
132181 prop := propagation .TextMapPropagator (propagation.Baggage {})
133182 tests := []struct {
0 commit comments