MCPcopy
hub / github.com/kopia/kopia / TestGatherBytesReaderAtErrorResponses

Function TestGatherBytesReaderAtErrorResponses

internal/gather/gather_bytes_test.go:187–251  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

185}
186
187func TestGatherBytesReaderAtErrorResponses(t *testing.T) {
188 // 3.7 times the internal chunk size
189 contentBuf := make([]byte, int(float64(defaultAllocator.chunkSize)*3.7))
190 for i := range contentBuf {
191 contentBuf[i] = uint8(i % math.MaxUint8)
192 }
193
194 tcs := []struct {
195 inBsLen int
196 inOff int64
197 expectErr error
198 expectN int
199 }{
200 {
201 inBsLen: 1 << 10,
202 inOff: -1,
203 expectErr: ErrInvalidOffset,
204 expectN: 0,
205 },
206 {
207 inBsLen: 1 << 10,
208 inOff: math.MaxInt64,
209 expectErr: io.EOF,
210 expectN: 0,
211 },
212 {
213 inBsLen: 0,
214 inOff: -1,
215 expectErr: ErrInvalidOffset,
216 expectN: 0,
217 },
218 {
219 inBsLen: 0,
220 inOff: math.MaxInt64,
221 expectN: 0,
222 },
223 }
224 for i, tc := range tcs {
225 t.Run(fmt.Sprintf("%d: %d %d %d", i, tc.inBsLen, tc.inOff, tc.expectN), func(t *testing.T) {
226 // tmp is an empty buffer that will supply some bytes
227 // for testing
228 var wrt WriteBuffer
229 defer wrt.Close()
230
231 wrt.Append(contentBuf)
232 require.Equalf(t, defaultAllocator.chunkSize, wrt.alloc.chunkSize,
233 "this test expects that the default-allocator will be used, but we are using: %#v", wrt.alloc)
234
235 // get the reader out of the WriteBuffer so we can read what was written
236 // (presume all 0s)
237 reader := wrt.inner.Reader()
238 defer reader.Close() //nolint:errcheck
239
240 // get the reader as a ReaderAt
241 readerAt := testutil.EnsureType[io.ReaderAt](t, reader)
242
243 // make an output buffer of the required length
244 bs := make([]byte, tc.inBsLen)

Callers

nothing calls this directly

Calls 8

CloseMethod · 0.95
AppendMethod · 0.95
EnsureTypeFunction · 0.92
EqualMethod · 0.80
RunMethod · 0.65
ReaderMethod · 0.65
CloseMethod · 0.65
ReadAtMethod · 0.45

Tested by

no test coverage detected