MCPcopy
hub / github.com/grpc/grpc-go / TestAppendToOutgoingContext

Method TestAppendToOutgoingContext

metadata/metadata_test.go:281–307  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

279}
280
281func (s) TestAppendToOutgoingContext(t *testing.T) {
282 // Pre-existing metadata
283 tCtx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
284 defer cancel()
285 ctx := NewOutgoingContext(tCtx, Pairs("k1", "v1", "k2", "v2"))
286 ctx = AppendToOutgoingContext(ctx, "k1", "v3")
287 ctx = AppendToOutgoingContext(ctx, "k1", "v4")
288 md, ok := FromOutgoingContext(ctx)
289 if !ok {
290 t.Errorf("Expected MD to exist in ctx, but got none")
291 }
292 want := Pairs("k1", "v1", "k1", "v3", "k1", "v4", "k2", "v2")
293 if !reflect.DeepEqual(md, want) {
294 t.Errorf("context's metadata is %v, want %v", md, want)
295 }
296
297 // No existing metadata
298 ctx = AppendToOutgoingContext(tCtx, "k1", "v1")
299 md, ok = FromOutgoingContext(ctx)
300 if !ok {
301 t.Errorf("Expected MD to exist in ctx, but got none")
302 }
303 want = Pairs("k1", "v1")
304 if !reflect.DeepEqual(md, want) {
305 t.Errorf("context's metadata is %v, want %v", md, want)
306 }
307}
308
309func (s) TestAppendToOutgoingContext_Repeated(t *testing.T) {
310 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)

Callers

nothing calls this directly

Calls 5

NewOutgoingContextFunction · 0.85
PairsFunction · 0.85
AppendToOutgoingContextFunction · 0.85
FromOutgoingContextFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected