MCPcopy
hub / github.com/rclone/rclone / TestRWFileHandleReadAt

Function TestRWFileHandleReadAt

vfs/read_write_test.go:166–213  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

164}
165
166func TestRWFileHandleReadAt(t *testing.T) {
167 _, _, fh := rwHandleCreateReadOnly(t)
168
169 // read from start
170 buf := make([]byte, 1)
171 n, err := fh.ReadAt(buf, 0)
172 require.NoError(t, err)
173 assert.Equal(t, 1, n)
174 assert.Equal(t, "0", string(buf[:n]))
175
176 // seek forwards
177 n, err = fh.ReadAt(buf, 5)
178 require.NoError(t, err)
179 assert.Equal(t, 1, n)
180 assert.Equal(t, "5", string(buf[:n]))
181
182 // seek backwards
183 n, err = fh.ReadAt(buf, 1)
184 require.NoError(t, err)
185 assert.Equal(t, 1, n)
186 assert.Equal(t, "1", string(buf[:n]))
187
188 // read exactly to the end
189 buf = make([]byte, 6)
190 n, err = fh.ReadAt(buf, 10)
191 require.NoError(t, err)
192 assert.Equal(t, 6, n)
193 assert.Equal(t, "abcdef", string(buf[:n]))
194
195 // read off the end
196 buf = make([]byte, 256)
197 n, err = fh.ReadAt(buf, 10)
198 assert.Equal(t, io.EOF, err)
199 assert.Equal(t, 6, n)
200 assert.Equal(t, "abcdef", string(buf[:n]))
201
202 // read starting off the end
203 n, err = fh.ReadAt(buf, 100)
204 assert.Equal(t, io.EOF, err)
205 assert.Equal(t, 0, n)
206
207 // Properly close the file
208 assert.NoError(t, fh.Close())
209
210 // check reading on closed file
211 _, err = fh.ReadAt(buf, 100)
212 assert.Equal(t, ECLOSED, err)
213}
214
215func TestRWFileHandleFlushRead(t *testing.T) {
216 _, _, fh := rwHandleCreateReadOnly(t)

Callers

nothing calls this directly

Calls 4

rwHandleCreateReadOnlyFunction · 0.85
ReadAtMethod · 0.65
CloseMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…