(t *testing.T)
| 91 | } |
| 92 | |
| 93 | func TestError(t *testing.T) { |
| 94 | for _, doNotLog := range []bool{true, false} { |
| 95 | var stat string |
| 96 | if !doNotLog { |
| 97 | stat = "not " |
| 98 | } |
| 99 | t.Run(fmt.Sprintf("test header when DoNotLogErrorHeaderKey is %spresent", stat), func(t *testing.T) { |
| 100 | server, err := newTestServer(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| 101 | if doNotLog { |
| 102 | w.Header().Set(DoNotLogErrorHeaderKey, "true") |
| 103 | } |
| 104 | // Does a Fprintln, injecting a newline. |
| 105 | http.Error(w, "foo", http.StatusInternalServerError) |
| 106 | })) |
| 107 | require.NoError(t, err) |
| 108 | defer server.grpcServer.GracefulStop() |
| 109 | |
| 110 | client, err := NewClient(server.URL) |
| 111 | require.NoError(t, err) |
| 112 | |
| 113 | req, err := http.NewRequest("GET", "/hello", &bytes.Buffer{}) |
| 114 | require.NoError(t, err) |
| 115 | |
| 116 | req = req.WithContext(user.InjectOrgID(context.Background(), "1")) |
| 117 | recorder := httptest.NewRecorder() |
| 118 | client.ServeHTTP(recorder, req) |
| 119 | |
| 120 | assert.Equal(t, "foo\n", recorder.Body.String()) |
| 121 | assert.Equal(t, 500, recorder.Code) |
| 122 | assert.NotContains(t, recorder.Header(), DoNotLogErrorHeaderKey) |
| 123 | }) |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | func TestServerHandleDoNotLogError(t *testing.T) { |
| 128 | testCases := map[string]struct { |
nothing calls this directly
no test coverage detected