@@ -15,6 +15,7 @@ package baggage
15
15
16
16
import (
17
17
"context"
18
+ "strings"
18
19
"sync/atomic"
19
20
"testing"
20
21
@@ -40,17 +41,20 @@ type grpcBaggage struct {
40
41
grpcapp * procgrpc.App
41
42
daprd * daprd.Daprd
42
43
43
- baggage atomic.Bool
44
+ baggage atomic.Bool
45
+ baggageVals atomic.Value
44
46
}
45
47
46
48
func (g * grpcBaggage ) Setup (t * testing.T ) []framework.Option {
47
49
g .grpcapp = procgrpc .New (t ,
48
50
procgrpc .WithOnInvokeFn (func (ctx context.Context , in * common.InvokeRequest ) (* common.InvokeResponse , error ) {
49
51
if md , ok := grpcMetadata .FromIncomingContext (ctx ); ok {
50
- if _ , exists := md ["baggage" ]; exists {
52
+ if baggage , exists := md ["baggage" ]; exists {
51
53
g .baggage .Store (true )
54
+ g .baggageVals .Store (strings .Join (baggage , "," ))
52
55
} else {
53
56
g .baggage .Store (false )
57
+ g .baggageVals .Store ("" )
54
58
}
55
59
}
56
60
return nil , nil
@@ -86,6 +90,7 @@ func (g *grpcBaggage) Run(t *testing.T, ctx context.Context) {
86
90
require .NoError (t , err )
87
91
require .NotNil (t , svcresp )
88
92
assert .False (t , g .baggage .Load ())
93
+ assert .Equal (t , "" , g .baggageVals .Load ())
89
94
})
90
95
91
96
t .Run ("baggage header provided" , func (t * testing.T ) {
@@ -102,20 +107,22 @@ func (g *grpcBaggage) Run(t *testing.T, ctx context.Context) {
102
107
},
103
108
}
104
109
110
+ baggageVal := "key1=value1,key2=value2"
105
111
ctx = grpcMetadata .AppendToOutgoingContext (t .Context (),
106
- "baggage" , "key1=value1,key2=value2" ,
112
+ "baggage" , baggageVal ,
107
113
)
108
114
svcresp , err := client .InvokeService (ctx , & svcreq )
109
115
require .NoError (t , err )
110
116
require .NotNil (t , svcresp )
111
117
assert .True (t , g .baggage .Load ())
118
+ assert .Equal (t , baggageVal , g .baggageVals .Load ())
112
119
113
120
// Verify baggage header is in response metadata
114
121
md , ok := grpcMetadata .FromOutgoingContext (ctx )
115
122
require .True (t , ok )
116
123
baggage := md .Get ("baggage" )
117
124
require .Len (t , baggage , 1 )
118
- assert .Equal (t , "key1=value1,key2=value2" , baggage [0 ])
125
+ assert .Equal (t , baggageVal , baggage [0 ])
119
126
})
120
127
121
128
t .Run ("invalid baggage header" , func (t * testing.T ) {
0 commit comments