MCPcopy
hub / github.com/klauspost/compress / TestEncoderResetWithOptions

Function TestEncoderResetWithOptions

zstd/encoder_options_test.go:157–216  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

155}
156
157func TestEncoderResetWithOptions(t *testing.T) {
158 var buf bytes.Buffer
159 enc, err := NewWriter(&buf, WithEncoderLevel(SpeedFastest), WithEncoderCRC(true))
160 if err != nil {
161 t.Fatal(err)
162 }
163 defer enc.Close()
164
165 // Test changing safe options
166 t.Run("change-crc", func(t *testing.T) {
167 err := enc.ResetWithOptions(&buf, WithEncoderCRC(false))
168 if err != nil {
169 t.Errorf("ResetWithOptions should allow changing CRC: %v", err)
170 }
171 })
172
173 t.Run("change-padding", func(t *testing.T) {
174 err := enc.ResetWithOptions(&buf, WithEncoderPadding(64))
175 if err != nil {
176 t.Errorf("ResetWithOptions should allow changing padding: %v", err)
177 }
178 })
179
180 // Test error when changing unsafe options
181 t.Run("change-level-error", func(t *testing.T) {
182 err := enc.ResetWithOptions(&buf, WithEncoderLevel(SpeedBestCompression))
183 if err == nil {
184 t.Error("ResetWithOptions should error when changing level")
185 }
186 })
187
188 t.Run("change-concurrency-error", func(t *testing.T) {
189 err := enc.ResetWithOptions(&buf, WithEncoderConcurrency(99))
190 if err == nil {
191 t.Error("ResetWithOptions should error when changing concurrency")
192 }
193 })
194
195 t.Run("change-window-error", func(t *testing.T) {
196 err := enc.ResetWithOptions(&buf, WithWindowSize(1<<15))
197 if err == nil {
198 t.Error("ResetWithOptions should error when changing window size")
199 }
200 })
201
202 t.Run("change-lowmem-error", func(t *testing.T) {
203 err := enc.ResetWithOptions(&buf, WithLowerEncoderMem(true))
204 if err == nil {
205 t.Error("ResetWithOptions should error when changing lowMem")
206 }
207 })
208
209 // Test same value is allowed
210 t.Run("same-level-ok", func(t *testing.T) {
211 err := enc.ResetWithOptions(&buf, WithEncoderLevel(SpeedFastest))
212 if err != nil {
213 t.Errorf("ResetWithOptions should allow same level: %v", err)
214 }

Callers

nothing calls this directly

Calls 11

CloseMethod · 0.95
WithEncoderLevelFunction · 0.85
WithEncoderCRCFunction · 0.85
WithEncoderPaddingFunction · 0.85
WithEncoderConcurrencyFunction · 0.85
WithWindowSizeFunction · 0.85
WithLowerEncoderMemFunction · 0.85
FatalMethod · 0.80
NewWriterFunction · 0.70
ResetWithOptionsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…