MCPcopy
hub / github.com/wal-g/wal-g / TestCascadeFileCloser

Function TestCascadeFileCloser

internal/compression_structures_test.go:30–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28}
29
30func TestCascadeFileCloser(t *testing.T) {
31 for _, testCase := range tests {
32 b := &testtools.BufCloser{Buffer: bytes.NewBufferString(testCase.testString), Err: false}
33 lz := &utility.CascadeWriteCloser{
34 WriteCloser: GetLz4Compressor().NewWriter(b),
35 Underlying: b,
36 }
37
38 random := make([]byte, testCase.written)
39 _, err := rand.Read(random)
40 if err != nil {
41 t.Log(err)
42 }
43
44 n, err := lz.Write(random)
45 assert.NoErrorf(t, err, "compress: CascadeWriteCloser expected `<nil>` but got %v", err)
46 assert.Equalf(t, n, testCase.written,
47 "compress: CascadeWriteCloser expected %d bytes written but got %d", testCase.written, n)
48
49 err = lz.Close()
50 assert.NoErrorf(t, err, "compress: CascadeWriteCloser expected `<nil>` but got %v", err)
51
52 b.Err = true
53
54 err = lz.Close()
55 assert.Errorf(t, err, "compress: Underlying writer expected to close with error but got `<nil>`")
56
57 }
58}
59
60func TestCascadeFileCloserError(t *testing.T) {
61 mock := &testtools.ErrorWriteCloser{}

Callers

nothing calls this directly

Calls 6

CloseMethod · 0.95
GetLz4CompressorFunction · 0.85
ErrorfMethod · 0.80
NewWriterMethod · 0.65
ReadMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected