(t *testing.T)
| 23 | ) |
| 24 | |
| 25 | func TestErrorWriter(t *testing.T) { |
| 26 | t.Parallel() |
| 27 | t.Run("RequireConnectProtocolHeader", func(t *testing.T) { |
| 28 | t.Parallel() |
| 29 | writer := NewErrorWriter(WithRequireConnectProtocolHeader()) |
| 30 | t.Run("Unary", func(t *testing.T) { |
| 31 | t.Parallel() |
| 32 | req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "http://localhost", nil) |
| 33 | req.Header.Set("Content-Type", connectUnaryContentTypePrefix+codecNameJSON) |
| 34 | assert.False(t, writer.IsSupported(req)) |
| 35 | req.Header.Set(connectHeaderProtocolVersion, connectProtocolVersion) |
| 36 | assert.True(t, writer.IsSupported(req)) |
| 37 | }) |
| 38 | t.Run("UnaryGET", func(t *testing.T) { |
| 39 | t.Parallel() |
| 40 | req := httptest.NewRequestWithContext(t.Context(), http.MethodGet, "http://localhost", nil) |
| 41 | assert.False(t, writer.IsSupported(req)) |
| 42 | query := req.URL.Query() |
| 43 | query.Set(connectUnaryConnectQueryParameter, connectUnaryConnectQueryValue) |
| 44 | req.URL.RawQuery = query.Encode() |
| 45 | assert.True(t, writer.IsSupported(req)) |
| 46 | }) |
| 47 | t.Run("Stream", func(t *testing.T) { |
| 48 | t.Parallel() |
| 49 | req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "http://localhost", nil) |
| 50 | req.Header.Set("Content-Type", connectStreamingContentTypePrefix+codecNameJSON) |
| 51 | assert.True(t, writer.IsSupported(req)) // ignores WithRequireConnectProtocolHeader |
| 52 | req.Header.Set(connectHeaderProtocolVersion, connectProtocolVersion) |
| 53 | assert.True(t, writer.IsSupported(req)) |
| 54 | }) |
| 55 | }) |
| 56 | t.Run("Protocols", func(t *testing.T) { |
| 57 | t.Parallel() |
| 58 | writer := NewErrorWriter() // All supported by default |
| 59 | t.Run("ConnectUnary", func(t *testing.T) { |
| 60 | t.Parallel() |
| 61 | req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "http://localhost", nil) |
| 62 | req.Header.Set("Content-Type", connectUnaryContentTypePrefix+codecNameJSON) |
| 63 | assert.True(t, writer.IsSupported(req)) |
| 64 | }) |
| 65 | t.Run("ConnectUnaryGET", func(t *testing.T) { |
| 66 | t.Parallel() |
| 67 | req := httptest.NewRequestWithContext(t.Context(), http.MethodGet, "http://localhost", nil) |
| 68 | assert.True(t, writer.IsSupported(req)) |
| 69 | }) |
| 70 | t.Run("ConnectStream", func(t *testing.T) { |
| 71 | t.Parallel() |
| 72 | req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "http://localhost", nil) |
| 73 | req.Header.Set("Content-Type", connectStreamingContentTypePrefix+codecNameJSON) |
| 74 | assert.True(t, writer.IsSupported(req)) |
| 75 | }) |
| 76 | t.Run("GRPC", func(t *testing.T) { |
| 77 | t.Parallel() |
| 78 | req := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "http://localhost", nil) |
| 79 | req.Header.Set("Content-Type", grpcContentTypeDefault) |
| 80 | assert.True(t, writer.IsSupported(req)) |
| 81 | req.Header.Set("Content-Type", grpcContentTypePrefix+"json") |
| 82 | assert.True(t, writer.IsSupported(req)) |
nothing calls this directly
no test coverage detected