(t *testing.T)
| 23 | ) |
| 24 | |
| 25 | func TestWriteResponse(t *testing.T) { |
| 26 | t.Run("new response has empty headers", func(t *testing.T) { |
| 27 | resp := NewWriteResponse() |
| 28 | if len(resp.ExtraHeaders()) != 0 { |
| 29 | t.Errorf("expected empty headers, got %v", resp.ExtraHeaders()) |
| 30 | } |
| 31 | }) |
| 32 | |
| 33 | t.Run("setters and getters", func(t *testing.T) { |
| 34 | resp := NewWriteResponse() |
| 35 | |
| 36 | resp.SetStatusCode(http.StatusOK) |
| 37 | if got := resp.StatusCode(); got != http.StatusOK { |
| 38 | t.Errorf("expected status code %d, got %d", http.StatusOK, got) |
| 39 | } |
| 40 | |
| 41 | stats := WriteResponseStats{ |
| 42 | Samples: 10, |
| 43 | Histograms: 5, |
| 44 | Exemplars: 2, |
| 45 | confirmed: true, |
| 46 | } |
| 47 | resp.Add(stats) |
| 48 | if diff := cmp.Diff(stats, resp.Stats(), cmpopts.IgnoreUnexported(WriteResponseStats{})); diff != "" { |
| 49 | t.Errorf("stats mismatch (-want +got):\n%s", diff) |
| 50 | } |
| 51 | |
| 52 | toAdd := WriteResponseStats{ |
| 53 | Samples: 10, |
| 54 | Histograms: 5, |
| 55 | Exemplars: 2, |
| 56 | confirmed: true, |
| 57 | } |
| 58 | resp.Add(toAdd) |
| 59 | if diff := cmp.Diff(WriteResponseStats{ |
| 60 | Samples: 20, |
| 61 | Histograms: 10, |
| 62 | Exemplars: 4, |
| 63 | confirmed: true, |
| 64 | }, resp.Stats(), cmpopts.IgnoreUnexported(WriteResponseStats{})); diff != "" { |
| 65 | t.Errorf("stats mismatch (-want +got):\n%s", diff) |
| 66 | } |
| 67 | |
| 68 | resp.SetExtraHeader("Test-Header", "test-value") |
| 69 | if got := resp.ExtraHeaders().Get("Test-Header"); got != "test-value" { |
| 70 | t.Errorf("expected header value %q, got %q", "test-value", got) |
| 71 | } |
| 72 | }) |
| 73 | |
| 74 | t.Run("set headers on response writer", func(t *testing.T) { |
| 75 | resp := NewWriteResponse() |
| 76 | resp.Add(WriteResponseStats{ |
| 77 | Samples: 10, |
| 78 | Histograms: 5, |
| 79 | Exemplars: 2, |
| 80 | confirmed: true, |
| 81 | }) |
| 82 | resp.SetExtraHeader("Custom-Header", "custom-value") |
nothing calls this directly
no test coverage detected