MCPcopy Index your code
hub / github.com/ContentSquare/chproxy / TestDecompression

Function TestDecompression

utils_test.go:176–281  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

174)
175
176func TestDecompression(t *testing.T) {
177 testCases := []struct {
178 name string
179 compressedQuery string
180 f func(*http.Request) error
181 }{
182 {
183 "full LZ4",
184 lz4TestQuery,
185 func(req *http.Request) error {
186 q, err := getFullQuery(req)
187 if err != nil {
188 return err
189 }
190 checkResponse(t, req.Body, lz4TestQuery)
191 if string(q) != testQuery {
192 return fmt.Errorf("got: %q; expected %q", string(q), testQuery)
193 }
194 return nil
195 },
196 },
197 {
198 "snippet LZ4",
199 lz4TestQuery,
200 func(req *http.Request) error {
201 q := getQuerySnippet(req)
202 if q[:100] != string(testQuery[:100]) {
203 return fmt.Errorf("got: %q; expected: %q", q[:100], testQuery[:100])
204 }
205 return nil
206 },
207 },
208 {
209 "partial LZ4",
210 lz4TestQuery + "foobar", // write whatever to buf to make the data partially invalid
211 func(req *http.Request) error {
212 q := getQuerySnippet(req)
213 if q[:50] != testQuery[:50] {
214 return fmt.Errorf("got: %q; expected: %q", q[:50], testQuery[:50])
215 }
216 return nil
217 },
218 },
219 {
220 "invalid compression",
221 "foobar", // write totally invalid data and treat it as compressed
222 func(req *http.Request) error {
223 q := getQuerySnippet(req)
224 if q != "foobar" {
225 t.Fatalf("got: %q; expected: %q", q, "foobar")
226 }
227 return nil
228 },
229 },
230 {
231 "full ZSTD",
232 zstdTestQuery,
233 func(req *http.Request) error {

Callers

nothing calls this directly

Calls 3

getFullQueryFunction · 0.85
checkResponseFunction · 0.85
getQuerySnippetFunction · 0.85

Tested by

no test coverage detected