MCPcopy Index your code
hub / github.com/coder/coder / TestCompressorPresetHeaders

Function TestCompressorPresetHeaders

coderd/cachecompress/compress_internal_test.go:158–191  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

156func (nopEncoder) Close() error { return nil }
157
158func TestCompressorPresetHeaders(t *testing.T) {
159 t.Parallel()
160
161 logger := testutil.Logger(t)
162 tempDir := t.TempDir()
163 cacheDir := filepath.Join(tempDir, "cache")
164 err := os.MkdirAll(cacheDir, 0o700)
165 require.NoError(t, err)
166 srcDir := filepath.Join(tempDir, "src")
167 err = os.MkdirAll(srcDir, 0o700)
168 require.NoError(t, err)
169 err = os.WriteFile(filepath.Join(srcDir, "file.html"), []byte("textstring"), 0o600)
170 require.NoError(t, err)
171
172 compressor := NewCompressor(logger, 5, cacheDir, http.FS(os.DirFS(srcDir)))
173
174 for range 2 {
175 ctx := testutil.Context(t, testutil.WaitShort)
176 req := httptest.NewRequestWithContext(ctx, "GET", "/file.html", nil)
177 req.Header.Set("Accept-Encoding", "gzip")
178
179 respRec := httptest.NewRecorder()
180 respRec.Header().Set("X-Original-Content-Length", "10")
181 respRec.Header().Set("ETag", `"abc123"`)
182
183 compressor.ServeHTTP(respRec, req)
184 resp := respRec.Result()
185
186 require.Equal(t, http.StatusOK, resp.StatusCode)
187 require.Equal(t, []string{"10"}, resp.Header.Values("X-Original-Content-Length"))
188 require.Equal(t, []string{`"abc123"`}, resp.Header.Values("ETag"))
189 require.NoError(t, resp.Body.Close())
190 }
191}
192
193// nolint: tparallel // we want to assert the state of the cache, so run synchronously
194func TestCompressorHeadings(t *testing.T) {

Callers

nothing calls this directly

Calls 12

ServeHTTPMethod · 0.95
LoggerFunction · 0.92
ContextFunction · 0.92
NewCompressorFunction · 0.85
MkdirAllMethod · 0.80
TempDirMethod · 0.65
WriteFileMethod · 0.65
SetMethod · 0.65
CloseMethod · 0.65
HeaderMethod · 0.45
ResultMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected