(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func 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 | |
| 39 | func TestAnnotateContext_WorksWithNoIncomingHeaders(t *testing.T) { |
| 40 | ctx := context.Background() |
nothing calls this directly
no test coverage detected