MCPcopy
hub / github.com/rclone/rclone / TestWriteFileHandleWriteAt

Function TestWriteFileHandleWriteAt

vfs/write_test.go:194–236  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

192}
193
194func TestWriteFileHandleWriteAt(t *testing.T) {
195 r, vfs, fh := writeHandleCreate(t)
196
197 // Preconditions
198 assert.Equal(t, int64(0), fh.offset)
199 assert.False(t, fh.writeCalled)
200
201 // Write the data
202 n, err := fh.WriteAt([]byte("hello"), 0)
203 assert.NoError(t, err)
204 assert.Equal(t, 5, n)
205
206 // After write
207 assert.Equal(t, int64(5), fh.offset)
208 assert.True(t, fh.writeCalled)
209
210 // Check can't seek
211 n, err = fh.WriteAt([]byte("hello"), 100)
212 assert.Equal(t, ESPIPE, err)
213 assert.Equal(t, 0, n)
214
215 // Write more data
216 n, err = fh.WriteAt([]byte(" world"), 5)
217 assert.NoError(t, err)
218 assert.Equal(t, 6, n)
219
220 // Close
221 assert.NoError(t, fh.Close())
222
223 // Check can't write on closed handle
224 n, err = fh.WriteAt([]byte("hello"), 0)
225 assert.Equal(t, ECLOSED, err)
226 assert.Equal(t, 0, n)
227
228 // check vfs
229 root, err := vfs.Root()
230 require.NoError(t, err)
231 checkListing(t, root, []string{"file1,11,false"})
232
233 // check the underlying r.Fremote but not the modtime
234 file1 := fstest.NewItem("file1", "hello world", t1)
235 fstest.CheckListingWithPrecision(t, r.Fremote, []fstest.Item{file1}, []string{}, fs.ModTimeNotSupported)
236}
237
238func TestWriteFileHandleFlush(t *testing.T) {
239 _, vfs, fh := writeHandleCreate(t)

Callers

nothing calls this directly

Calls 8

NewItemFunction · 0.92
writeHandleCreateFunction · 0.85
checkListingFunction · 0.70
WriteAtMethod · 0.65
CloseMethod · 0.65
RootMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…