| 1 | package toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/" |
| 5 | "errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/" |
| 6 | "ioscip-go gomod github.com/golang/go/src go1.25.0 io/" |
| 7 | "osscip-go gomod github.com/golang/go/src go1.25.0 os/" |
| 8 | "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/" |
| 9 | |
| 10 | "github.com/git-lfs/git-lfs/v3/internal/testutilscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/internal/testutil`/" |
| 11 | "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/" |
| 12 | "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/" |
| 13 | ) |
| 14 | |
| 15 | func TestBothCallbackReadersInvokeCallbackOnEagerEOFscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/TestBothCallbackReadersInvokeCallbackOnEagerEOF().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 16 | var ( |
| 17 | calls int |
| 18 | actualTotalSize int64 |
| 19 | actualReadSoFar int64 |
| 20 | actualReadSinceLast int |
| 21 | ) |
| 22 | |
| 23 | cb := func(totalSize int64, readSoFar int64, readSinceLast int) error { |
| 24 | calls++ |
| 25 | actualTotalSize = totalSize |
| 26 | actualReadSoFar = readSoFar |
| 27 | actualReadSinceLast = readSinceLast |
| 28 | |
| 29 | return nil |
| 30 | } |
| 31 | |
| 32 | // We simulate a larger buffer which has not yet been fully read. |
| 33 | buf := []byte{0x1} |
| 34 | bufSize := len(buf) |
| 35 | initialTotalSize := 3 * int64(bufSize) |
| 36 | initialReadSize := initialTotalSize - int64(bufSize) |
| 37 | |
| 38 | r := NewCallbackReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewCallbackReader().(testutilscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/internal/testutil`/.NewEagerEOFByteReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/internal/testutil`/NewEagerEOFByteReader().(buf), initialTotalSize, cb) |
| 39 | br := NewBodyWithCallbackscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewBodyWithCallback().(testutilscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/internal/testutil`/.NewEagerEOFByteReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/internal/testutil`/NewEagerEOFByteReader().(buf), initialTotalSize, cb) |
| 40 | r.statescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/CallbackReader#state..readSizescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/callbackState#readSize. = initialReadSize |
| 41 | br.statescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/BodyWithCallback#state..readSizescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/callbackState#readSize. = initialReadSize |
| 42 | |
| 43 | p := make([]byte, bufSize+1) |
| 44 | |
| 45 | for _, reader := range []ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Readerscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#{r, br} { |
| 46 | t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("testing with reader: %T", reader) |
| 47 | |
| 48 | n, err := reader.Readscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#Read().(p) |
| 49 | |
| 50 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, bufSize, n) |
| 51 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, ioscip-go gomod github.com/golang/go/src go1.25.0 io/.EOFscip-go gomod github.com/golang/go/src go1.25.0 io/EOF., err) |
| 52 | |
| 53 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, 1, calls, "expected 1 call to callback, got %d", calls) |
| 54 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.EqualValuesscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/EqualValues().(t, initialTotalSize, actualTotalSize) |
| 55 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.EqualValuesscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/EqualValues().(t, initialTotalSize, actualReadSoFar) |
| 56 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, bufSize, actualReadSinceLast) |
| 57 | |
| 58 | // Read again and check that no callback is made after last |
| 59 | // byte has been read (since the simulated initial total |
| 60 | // matched the simulated number of bytes read). |
| 61 | calls = 0 |
| 62 | |
| 63 | n, err = reader.Readscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#Read().(p) |
| 64 | |
| 65 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Zeroscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Zero().(t, n) |
| 66 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, ioscip-go gomod github.com/golang/go/src go1.25.0 io/.EOFscip-go gomod github.com/golang/go/src go1.25.0 io/EOF., err) |
| 67 | |
| 68 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Zeroscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Zero().(t, calls, "expected no call to callback, got %d", calls) |
| 69 | |
| 70 | calls = 0 |
| 71 | actualTotalSize = 0 |
| 72 | actualReadSoFar = 0 |
| 73 | actualReadSinceLast = 0 |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | func TestBothCallbackReadersCountReadsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/TestBothCallbackReadersCountReads().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 78 | var actualReadSoFar int64 |
| 79 | |
| 80 | cb := func(totalSize int64, readSoFar int64, readSinceLast int) error { |
| 81 | actualReadSoFar = readSoFar |
| 82 | |
| 83 | return nil |
| 84 | } |
| 85 | |
| 86 | buf := []byte{0x1, 0x2, 0x3, 0x4} |
| 87 | bufSize := len(buf) |
| 88 | |
| 89 | r := NewCallbackReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewCallbackReader().(bytesscip-go gomod github.com/golang/go/src go1.25.0 bytes/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 bytes/NewReader().(buf), int64(bufSize), cb) |
| 90 | br := NewBodyWithCallbackscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewBodyWithCallback().(NewClosingByteReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewClosingByteReader().(buf), int64(bufSize), cb) |
| 91 | |
| 92 | p := make([]byte, 1) |
| 93 | |
| 94 | for _, reader := range []ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Readerscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#{r, br} { |
| 95 | t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("testing with reader: %T", reader) |
| 96 | |
| 97 | for i := 1; i <= bufSize; i++ { |
| 98 | n, err := reader.Readscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#Read().(p) |
| 99 | |
| 100 | // The underlying bytes.Reader should always return |
| 101 | // a nil error when the last byte is read. |
| 102 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, 1, n) |
| 103 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Nil().(t, err) |
| 104 | |
| 105 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.EqualValuesscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/EqualValues().(t, i, actualReadSoFar) |
| 106 | } |
| 107 | |
| 108 | actualReadSoFar = 0 |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | func TestBothCallbackReadersPreferCallbackErrorOverEOFscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/TestBothCallbackReadersPreferCallbackErrorOverEOF().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 113 | cbErr := errorsscip-go gomod github.com/golang/go/src go1.25.0 errors/.Newscip-go gomod github.com/golang/go/src go1.25.0 errors/New().("callback error") |
| 114 | cb := func(totalSize int64, readSoFar int64, readSinceLast int) error { |
| 115 | return cbErr |
| 116 | } |
| 117 | |
| 118 | buf := []byte{0x1, 0x2} |
| 119 | bufSize := len(buf) |
| 120 | |
| 121 | r := NewCallbackReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewCallbackReader().(testutilscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/internal/testutil`/.NewEagerEOFByteReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/internal/testutil`/NewEagerEOFByteReader().(buf), int64(bufSize), cb) |
| 122 | br := NewBodyWithCallbackscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewBodyWithCallback().(testutilscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/internal/testutil`/.NewEagerEOFByteReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/internal/testutil`/NewEagerEOFByteReader().(buf), int64(bufSize), cb) |
| 123 | |
| 124 | p := make([]byte, bufSize-1) |
| 125 | |
| 126 | for _, reader := range []ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Readerscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#{r, br} { |
| 127 | t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("testing with reader: %T", reader) |
| 128 | |
| 129 | n, err := reader.Readscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#Read().(p) |
| 130 | |
| 131 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, bufSize-1, n) |
| 132 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, cbErr, err) |
| 133 | |
| 134 | n, err = reader.Readscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#Read().(p) |
| 135 | |
| 136 | // We expect the EOF from EagerEOFByteReader's Read() method |
| 137 | // to be replaced with the callback function's own error. |
| 138 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, 1, n) |
| 139 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, cbErr, err) |
| 140 | |
| 141 | // We expect no callback to be performed when no bytes are |
| 142 | // available to be read, so no error should be returned. |
| 143 | n, err = reader.Readscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#Read().(p) |
| 144 | |
| 145 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Zeroscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Zero().(t, n) |
| 146 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, ioscip-go gomod github.com/golang/go/src go1.25.0 io/.EOFscip-go gomod github.com/golang/go/src go1.25.0 io/EOF., err) |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | func TestBothCallbackReadersSkipCallbackAfterReadErrorscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/TestBothCallbackReadersSkipCallbackAfterReadError().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 151 | var calls int |
| 152 | |
| 153 | cb := func(totalSize int64, readSoFar int64, readSinceLast int) error { |
| 154 | calls++ |
| 155 | |
| 156 | return nil |
| 157 | } |
| 158 | |
| 159 | buf := []byte{0x1, 0x2} |
| 160 | bufSize := len(buf) |
| 161 | |
| 162 | r := NewCallbackReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewCallbackReader().(testutilscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/internal/testutil`/.NewErrReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/internal/testutil`/NewErrReader().(ioscip-go gomod github.com/golang/go/src go1.25.0 io/.ErrUnexpectedEOFscip-go gomod github.com/golang/go/src go1.25.0 io/ErrUnexpectedEOF.), int64(bufSize), cb) |
| 163 | br := NewBodyWithCallbackscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewBodyWithCallback().(testutilscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/internal/testutil`/.NewErrReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/internal/testutil`/NewErrReader().(ioscip-go gomod github.com/golang/go/src go1.25.0 io/.ErrUnexpectedEOFscip-go gomod github.com/golang/go/src go1.25.0 io/ErrUnexpectedEOF.), int64(bufSize), cb) |
| 164 | |
| 165 | p := make([]byte, bufSize-1) |
| 166 | |
| 167 | for _, reader := range []ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Readerscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#{r, br} { |
| 168 | t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("testing with reader: %T", reader) |
| 169 | |
| 170 | n, err := reader.Readscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#Read().(p) |
| 171 | |
| 172 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Zeroscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Zero().(t, n) |
| 173 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, ioscip-go gomod github.com/golang/go/src go1.25.0 io/.ErrUnexpectedEOFscip-go gomod github.com/golang/go/src go1.25.0 io/ErrUnexpectedEOF., err) |
| 174 | |
| 175 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Zeroscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Zero().(t, calls, "expected no call to callback, got %d", calls) |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | func TestBothCallbackReadersInvokeCallbackOnEOFWhenTotalSizeIncorrectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/TestBothCallbackReadersInvokeCallbackOnEOFWhenTotalSizeIncorrect().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 180 | var ( |
| 181 | calls int |
| 182 | actualTotalSize int64 |
| 183 | actualReadSoFar int64 |
| 184 | ) |
| 185 | |
| 186 | cb := func(totalSize int64, readSoFar int64, readSinceLast int) error { |
| 187 | calls++ |
| 188 | actualTotalSize = totalSize |
| 189 | actualReadSoFar = readSoFar |
| 190 | |
| 191 | return nil |
| 192 | } |
| 193 | |
| 194 | buf := []byte{0x1, 0x2} |
| 195 | bufSize := len(buf) |
| 196 | |
| 197 | p := make([]byte, bufSize-1) |
| 198 | readBufSize := len(p) |
| 199 | |
| 200 | testCases := []struct { |
| 201 | description string |
| 202 | initialTotalSize int64 |
| 203 | }{ |
| 204 | {"initial total unknown", -1}, |
| 205 | {"initial total overestimated", int64(bufSize) + 1}, |
| 206 | {"initial total underestimated", int64(bufSize) - 1}, |
| 207 | } |
| 208 | |
| 209 | for _, tc := range testCases { |
| 210 | t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("testing with %s", tc.description) |
| 211 | |
| 212 | r := NewCallbackReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewCallbackReader().(testutilscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/internal/testutil`/.NewEagerEOFByteReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/internal/testutil`/NewEagerEOFByteReader().(buf), tc.initialTotalSize, cb) |
| 213 | br := NewBodyWithCallbackscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewBodyWithCallback().(testutilscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/internal/testutil`/.NewEagerEOFByteReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/internal/testutil`/NewEagerEOFByteReader().(buf), tc.initialTotalSize, cb) |
| 214 | |
| 215 | for _, reader := range []ioscip-go gomod github.com/golang/go/src go1.25.0 io/.Readerscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#{r, br} { |
| 216 | t.Logfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Logf().("testing with reader: %T", reader) |
| 217 | |
| 218 | n, err := reader.Readscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#Read().(p) |
| 219 | |
| 220 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, readBufSize, n) |
| 221 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Nil().(t, err) |
| 222 | |
| 223 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, 1, calls, "expected 1 call to callback, got %d", calls) |
| 224 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.EqualValuesscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/EqualValues().(t, tc.initialTotalSize, actualTotalSize) |
| 225 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.EqualValuesscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/EqualValues().(t, readBufSize, actualReadSoFar) |
| 226 | |
| 227 | n, err = reader.Readscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#Read().(p) |
| 228 | |
| 229 | // We expect an immediate EOF from the EagerEOFByteReader's |
| 230 | // Read() method once the final byte has been read. |
| 231 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, 1, n) |
| 232 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, ioscip-go gomod github.com/golang/go/src go1.25.0 io/.EOFscip-go gomod github.com/golang/go/src go1.25.0 io/EOF., err) |
| 233 | |
| 234 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, 2, calls, "expected 2 calls to callback, got %d", calls) |
| 235 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.EqualValuesscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/EqualValues().(t, bufSize, actualTotalSize) |
| 236 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.EqualValuesscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/EqualValues().(t, bufSize, actualReadSoFar) |
| 237 | |
| 238 | // Read again and check that no callback is made after last |
| 239 | // byte has been read (since the updated total matched the |
| 240 | // number of bytes read). |
| 241 | calls = 0 |
| 242 | |
| 243 | n, err = reader.Readscip-go gomod github.com/golang/go/src go1.25.0 io/Reader#Read().(p) |
| 244 | |
| 245 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Zeroscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Zero().(t, n) |
| 246 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, ioscip-go gomod github.com/golang/go/src go1.25.0 io/.EOFscip-go gomod github.com/golang/go/src go1.25.0 io/EOF., err) |
| 247 | |
| 248 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Zeroscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Zero().(t, calls, "expected no call to callback, got %d", calls) |
| 249 | |
| 250 | actualTotalSize = 0 |
| 251 | actualReadSoFar = 0 |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | func TestBodyCallbackReaderUpdatesOffsetOnSeekscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/TestBodyCallbackReaderUpdatesOffsetOnSeek().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 257 | var calls int |
| 258 | |
| 259 | cb := func(totalSize int64, readSoFar int64, readSinceLast int) error { |
| 260 | calls++ |
| 261 | |
| 262 | return nil |
| 263 | } |
| 264 | |
| 265 | buf := []byte{0x1, 0x2, 0x3, 0x4} |
| 266 | bufSize := len(buf) |
| 267 | |
| 268 | br := NewBodyWithCallbackscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewBodyWithCallback().(NewClosingByteReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewClosingByteReader().(buf), int64(bufSize), cb) |
| 269 | |
| 270 | offset := 1 |
| 271 | br.Seekscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/BodyWithCallback#Seek().(int64(offset), ioscip-go gomod github.com/golang/go/src go1.25.0 io/.SeekStartscip-go gomod github.com/golang/go/src go1.25.0 io/SeekStart.) |
| 272 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.EqualValuesscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/EqualValues().(t, offset, br.statescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/BodyWithCallback#state..readSizescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/callbackState#readSize.) |
| 273 | |
| 274 | offset++ |
| 275 | br.Seekscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/BodyWithCallback#Seek().(1, ioscip-go gomod github.com/golang/go/src go1.25.0 io/.SeekCurrentscip-go gomod github.com/golang/go/src go1.25.0 io/SeekCurrent.) |
| 276 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.EqualValuesscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/EqualValues().(t, offset, br.statescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/BodyWithCallback#state..readSizescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/callbackState#readSize.) |
| 277 | |
| 278 | p := make([]byte, bufSize) |
| 279 | |
| 280 | n, err := br.Readscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/BodyWithCallback#Read().(p) |
| 281 | |
| 282 | // The underlying bytes.Reader should always return |
| 283 | // a nil error when the last byte is read. |
| 284 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, bufSize-offset, n) |
| 285 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Nil().(t, err) |
| 286 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, buf[offset:], p[:bufSize-offset]) |
| 287 | |
| 288 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, 1, calls, "expected 1 call to callback, got %d", calls) |
| 289 | |
| 290 | br.Seekscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/BodyWithCallback#Seek().(-1, ioscip-go gomod github.com/golang/go/src go1.25.0 io/.SeekEndscip-go gomod github.com/golang/go/src go1.25.0 io/SeekEnd.) |
| 291 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.EqualValuesscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/EqualValues().(t, bufSize-1, br.statescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/BodyWithCallback#state..readSizescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/callbackState#readSize.) |
| 292 | |
| 293 | n, err = br.Readscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/BodyWithCallback#Read().(p) |
| 294 | |
| 295 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, 1, n) |
| 296 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Nil().(t, err) |
| 297 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, buf[bufSize-1], p[0]) |
| 298 | |
| 299 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, 2, calls, "expected 2 calls to callback, got %d", calls) |
| 300 | } |
| 301 | |
| 302 | func TestBodyCallbackReaderResetsProgressscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/TestBodyCallbackReaderResetsProgress().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 303 | var ( |
| 304 | calls int |
| 305 | actualTotalSize int64 |
| 306 | actualReadSoFar int64 |
| 307 | actualReadSinceLast int |
| 308 | ) |
| 309 | |
| 310 | cb := func(totalSize int64, readSoFar int64, readSinceLast int) error { |
| 311 | calls++ |
| 312 | actualTotalSize = totalSize |
| 313 | actualReadSoFar = readSoFar |
| 314 | actualReadSinceLast = readSinceLast |
| 315 | |
| 316 | return nil |
| 317 | } |
| 318 | |
| 319 | buf := []byte{0x1, 0x2, 0x3, 0x4} |
| 320 | bufSize := len(buf) |
| 321 | |
| 322 | br := NewBodyWithCallbackscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewBodyWithCallback().(NewClosingByteReaderscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewClosingByteReader().(buf), int64(bufSize), cb) |
| 323 | |
| 324 | p := make([]byte, bufSize-1) |
| 325 | readBufSize := len(p) |
| 326 | |
| 327 | n, err := br.Readscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/BodyWithCallback#Read().(p) |
| 328 | |
| 329 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, readBufSize, n) |
| 330 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Nil().(t, err) |
| 331 | |
| 332 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, 1, calls, "expected 1 call to callback, got %d", calls) |
| 333 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.EqualValuesscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/EqualValues().(t, bufSize, actualTotalSize) |
| 334 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.EqualValuesscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/EqualValues().(t, readBufSize, actualReadSoFar) |
| 335 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, readBufSize, actualReadSinceLast) |
| 336 | |
| 337 | // Note that ResetProgress() is only used to pass a decrement |
| 338 | // to the callback, as the caller is expected to create a new |
| 339 | // underlying buffer and retry the read operation. |
| 340 | br.ResetProgressscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/BodyWithCallback#ResetProgress().() |
| 341 | |
| 342 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, 2, calls, "expected 2 calls to callback, got %d", calls) |
| 343 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.EqualValuesscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/EqualValues().(t, bufSize, actualTotalSize) |
| 344 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.EqualValuesscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/EqualValues().(t, readBufSize, actualReadSoFar) |
| 345 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, -readBufSize, actualReadSinceLast) |
| 346 | } |
| 347 | |
| 348 | func TestFileBodyCallbackReaderIgnoresClosescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/TestFileBodyCallbackReaderIgnoresClose().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) { |
| 349 | buf := []byte{0x1, 0x2, 0x3, 0x4} |
| 350 | bufSize := len(buf) |
| 351 | |
| 352 | filePath := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().() + "/testFileBodyCallback" |
| 353 | |
| 354 | err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.WriteFilescip-go gomod github.com/golang/go/src go1.25.0 os/WriteFile().(filePath, buf, 0644) |
| 355 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Nilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Nil().(t, err) |
| 356 | |
| 357 | f, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.Openscip-go gomod github.com/golang/go/src go1.25.0 os/Open().(filePath) |
| 358 | requirescip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/.Nilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/require`/Nil().(t, err) |
| 359 | defer f.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().() |
| 360 | |
| 361 | fbr := NewFileBodyWithCallbackscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewFileBodyWithCallback().(f, int64(bufSize), nil) |
| 362 | |
| 363 | // The underlying os.File should not be closed and reads should |
| 364 | // still proceed. |
| 365 | err = fbr.Closescip-go gomod github.com/golang/go/src go1.25.0 io/Closer#Close().() |
| 366 | |
| 367 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Nil().(t, err) |
| 368 | |
| 369 | p := make([]byte, bufSize-1) |
| 370 | |
| 371 | n, err := fbr.Readscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/BodyWithCallback#Read().(p) |
| 372 | |
| 373 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Equal().(t, bufSize-1, n) |
| 374 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Nil().(t, err) |
| 375 | |
| 376 | // Closing the underlying os.File should result in a read error. |
| 377 | err = f.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().() |
| 378 | |
| 379 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Nilscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Nil().(t, err) |
| 380 | |
| 381 | n, err = fbr.Readscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/BodyWithCallback#Read().(p) |
| 382 | |
| 383 | assertscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/.Errorscip-go gomod github.com/stretchr/testify v1.11.1 `github.com/stretchr/testify/assert`/Error().(t, err) |
| 384 | } |