Open opens the file for read. Call Close() on the returned io.ReadCloser This will break after reading the number of bytes in breaks
(ctx context.Context, options ...fs.OpenOption)
| 40 | // |
| 41 | // This will break after reading the number of bytes in breaks |
| 42 | func (o *reOpenTestObject) Open(ctx context.Context, options ...fs.OpenOption) (io.ReadCloser, error) { |
| 43 | // Lots of backends do this - make sure it works as it modifies options |
| 44 | fs.FixRangeOption(options, o.Size()) |
| 45 | gotHash := false |
| 46 | gotRange := false |
| 47 | startPos := int64(0) |
| 48 | for _, option := range options { |
| 49 | switch x := option.(type) { |
| 50 | case *fs.HashesOption: |
| 51 | gotHash = true |
| 52 | case *fs.RangeOption: |
| 53 | gotRange = true |
| 54 | startPos = x.Start |
| 55 | if o.unknownSize { |
| 56 | assert.Equal(o.t, int64(-1), x.End) |
| 57 | } |
| 58 | case *fs.SeekOption: |
| 59 | startPos = x.Offset |
| 60 | } |
| 61 | } |
| 62 | assert.Equal(o.t, o.wantStart, startPos) |
| 63 | // Check if ranging, mustn't have hash if offset != 0 |
| 64 | if gotHash && gotRange { |
| 65 | assert.Equal(o.t, int64(0), startPos) |
| 66 | } |
| 67 | rc, err := o.Object.Open(ctx, options...) |
| 68 | if err != nil { |
| 69 | return nil, err |
| 70 | } |
| 71 | if len(o.breaks) > 0 { |
| 72 | // Pop a breakpoint off |
| 73 | N := o.breaks[0] |
| 74 | o.breaks = o.breaks[1:] |
| 75 | o.wantStart += N |
| 76 | // If 0 then return an error immediately |
| 77 | if N == 0 { |
| 78 | return nil, errorTestError |
| 79 | } |
| 80 | // Read N bytes then an error |
| 81 | r := io.MultiReader(&io.LimitedReader{R: rc, N: N}, readers.ErrorReader{Err: errorTestError}) |
| 82 | // Wrap with Close in a new readCloser |
| 83 | rc = readCloser{Reader: r, Closer: rc} |
| 84 | } |
| 85 | return rc, nil |
| 86 | } |
| 87 | |
| 88 | func TestReOpen(t *testing.T) { |
| 89 | for _, testName := range []string{"Normal", "WithRangeOption", "WithSeekOption", "UnknownSize"} { |
nothing calls this directly
no test coverage detected