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

Function testBlock

flate/huffman_bit_writer_test.go:191–308  ·  view source on GitHub ↗

testBlock tests a block against its references, or regenerate the references, if "-update" flag is set.

(t *testing.T, test huffTest, ttype string)

Source from the content-addressed store, hash-verified

189// testBlock tests a block against its references,
190// or regenerate the references, if "-update" flag is set.
191func testBlock(t *testing.T, test huffTest, ttype string) {
192 if test.want != "" {
193 test.want = fmt.Sprintf(test.want, ttype)
194 }
195 const gotSuffix = ".got"
196 test.wantNoInput = fmt.Sprintf(test.wantNoInput, ttype)
197 tokens := indexTokens(test.tokens)
198 if *update {
199 if test.input != "" {
200 t.Logf("Updating %q", test.want)
201 input, err := os.ReadFile(test.input)
202 if err != nil {
203 t.Error(err)
204 return
205 }
206
207 f, err := os.Create(test.want)
208 if err != nil {
209 t.Error(err)
210 return
211 }
212 defer f.Close()
213 bw := newHuffmanBitWriter(f)
214 writeToType(t, ttype, bw, tokens, input)
215 }
216
217 t.Logf("Updating %q", test.wantNoInput)
218 f, err := os.Create(test.wantNoInput)
219 if err != nil {
220 t.Error(err)
221 return
222 }
223 defer f.Close()
224 bw := newHuffmanBitWriter(f)
225 writeToType(t, ttype, bw, tokens, nil)
226 return
227 }
228
229 if test.input != "" {
230 t.Logf("Testing %q", test.want)
231 input, err := os.ReadFile(test.input)
232 if err != nil {
233 t.Error(err)
234 return
235 }
236 want, err := os.ReadFile(test.want)
237 if err != nil {
238 t.Error(err)
239 return
240 }
241 var buf bytes.Buffer
242 bw := newHuffmanBitWriter(&buf)
243 writeToType(t, ttype, bw, tokens, input)
244
245 got := buf.Bytes()
246 if !bytes.Equal(got, want) {
247 t.Errorf("writeBlock did not yield expected result for file %q with input. See %q", test.want, test.want+gotSuffix)
248 if err := os.WriteFile(test.want+gotSuffix, got, 0666); err != nil {

Callers 3

TestWriteBlockFunction · 0.85
TestWriteBlockDynamicFunction · 0.85

Calls 11

indexTokensFunction · 0.85
newHuffmanBitWriterFunction · 0.85
writeToTypeFunction · 0.85
testWriterEOFFunction · 0.85
CreateMethod · 0.80
CloseMethod · 0.65
BytesMethod · 0.65
ResetMethod · 0.65
ErrorMethod · 0.45
resetMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…