MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / TestAnnotateContext_WorksWithEmpty

Function TestAnnotateContext_WorksWithEmpty

runtime/context_test.go:19–37  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestAnnotateContext_WorksWithEmpty(t *testing.T) {
20 ctx := context.Background()
21 expectedRPCName := "/example.Example/Example"
22 expectedHTTPPathPattern := "/v1"
23 request, err := http.NewRequestWithContext(ctx, "GET", "http://www.example.com/v1", nil)
24 if err != nil {
25 t.Fatalf("http.NewRequestWithContext(ctx, %q, %q, nil) failed with %v; want success", "GET", "http://www.example.com", err)
26 }
27 request.Header.Add("Some-Irrelevant-Header", "some value")
28 annotated, err := runtime.AnnotateContext(ctx, runtime.NewServeMux(), request, expectedRPCName, runtime.WithHTTPPathPattern(expectedHTTPPathPattern))
29 if err != nil {
30 t.Errorf("runtime.AnnotateContext(ctx, %#v) failed with %v; want success", request, err)
31 return
32 }
33 md, ok := metadata.FromOutgoingContext(annotated)
34 if !ok || len(md) != emptyForwardMetaCount {
35 t.Errorf("Expected %d metadata items in context; got %v", emptyForwardMetaCount, md)
36 }
37}
38
39func TestAnnotateContext_WorksWithNoIncomingHeaders(t *testing.T) {
40 ctx := context.Background()

Callers

nothing calls this directly

Calls 3

AnnotateContextFunction · 0.92
NewServeMuxFunction · 0.92
WithHTTPPathPatternFunction · 0.92

Tested by

no test coverage detected