(t *testing.T)
| 155 | } |
| 156 | |
| 157 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…