MCPcopy Create free account
hub / github.com/bodgit/sevenzip / TestOpenReader

Function TestOpenReader

reader_internal_test.go:286–414  ·  view source on GitHub ↗

nolint:funlen

(t *testing.T)

Source from the content-addressed store, hash-verified

284
285//nolint:funlen
286func TestOpenReader(t *testing.T) {
287 t.Parallel()
288
289 tables := []struct {
290 name string
291 fs func(tb testing.TB) afero.Fs
292 err error
293 }{
294 {
295 name: "ok",
296 fs: func(tb testing.TB) afero.Fs {
297 tb.Helper()
298
299 info := newMockFileInfo(tb)
300 info.On("Size").Return(int64(100)).Twice()
301
302 one := newMockFile(tb)
303 one.On("Stat").Return(info, nil).Once()
304 one.On("Close").Return(nil).Once()
305
306 two := newMockFile(tb)
307 two.On("Stat").Return(info, nil).Once()
308 two.On("Close").Return(nil).Once()
309
310 fs := newMockFs(tb)
311 fs.On("Open", "filename.7z.001").Return(one, nil).Once()
312 fs.On("Open", "filename.7z.002").Return(two, nil).Once()
313 fs.On("Open", "filename.7z.003").Return(nil, iofs.ErrNotExist).Once()
314
315 return fs
316 },
317 },
318 {
319 name: "first open error",
320 fs: func(tb testing.TB) afero.Fs {
321 tb.Helper()
322
323 fs := newMockFs(tb)
324 fs.On("Open", "filename.7z.001").Return(nil, iofs.ErrPermission).Once()
325
326 return fs
327 },
328 err: iofs.ErrPermission,
329 },
330 {
331 name: "first stat error",
332 fs: func(tb testing.TB) afero.Fs {
333 tb.Helper()
334
335 one := newMockFile(tb)
336 one.On("Stat").Return(nil, iofs.ErrPermission).Once()
337 one.On("Close").Return(nil).Once()
338
339 fs := newMockFs(tb)
340 fs.On("Open", "filename.7z.001").Return(one, nil).Once()
341
342 return fs
343 },

Callers

nothing calls this directly

Calls 5

newMockFileInfoFunction · 0.85
newMockFileFunction · 0.85
newMockFsFunction · 0.85
openReaderFunction · 0.85
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…