MCPcopy
hub / github.com/rclone/rclone / TestInternalUploadTempFileOperations

Function TestInternalUploadTempFileOperations

backend/cache/cache_upload_test.go:200–326  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

198}
199
200func TestInternalUploadTempFileOperations(t *testing.T) {
201 id := "tiutfo"
202 rootFs, boltDb := runInstance.newCacheFs(t, remoteName, id, true, true,
203 map[string]string{"tmp_upload_path": path.Join(runInstance.tmpUploadDir, id), "tmp_wait_time": "1h"})
204
205 boltDb.PurgeTempUploads()
206
207 // create some rand test data
208 runInstance.mkdir(t, rootFs, "test")
209 runInstance.writeRemoteString(t, rootFs, "test/one", "one content")
210
211 // check if it can be read
212 data1, err := runInstance.readDataFromRemote(t, rootFs, "test/one", 0, int64(len([]byte("one content"))), false)
213 require.NoError(t, err)
214 require.Equal(t, []byte("one content"), data1)
215 // validate that it exists in temp fs
216 _, err = os.Stat(path.Join(runInstance.tmpUploadDir, id, runInstance.encryptRemoteIfNeeded(t, "test/one")))
217 require.NoError(t, err)
218
219 // test DirMove - allowed
220 err = runInstance.dirMove(t, rootFs, "test", "second")
221 if err != errNotSupported {
222 require.NoError(t, err)
223 _, err = rootFs.NewObject(context.Background(), "test/one")
224 require.Error(t, err)
225 _, err = rootFs.NewObject(context.Background(), "second/one")
226 require.NoError(t, err)
227 // validate that it exists in temp fs
228 _, err = os.Stat(path.Join(runInstance.tmpUploadDir, id, runInstance.encryptRemoteIfNeeded(t, "test/one")))
229 require.Error(t, err)
230 _, err = os.Stat(path.Join(runInstance.tmpUploadDir, id, runInstance.encryptRemoteIfNeeded(t, "second/one")))
231 require.NoError(t, err)
232 _, err = boltDb.SearchPendingUpload(runInstance.encryptRemoteIfNeeded(t, path.Join(id, "test/one")))
233 require.Error(t, err)
234 var started bool
235 started, err = boltDb.SearchPendingUpload(runInstance.encryptRemoteIfNeeded(t, path.Join(id, "second/one")))
236 require.NoError(t, err)
237 require.False(t, started)
238 runInstance.mkdir(t, rootFs, "test")
239 runInstance.writeRemoteString(t, rootFs, "test/one", "one content")
240 }
241
242 // test Rmdir - allowed
243 err = runInstance.rm(t, rootFs, "test")
244 require.Error(t, err)
245 require.Contains(t, err.Error(), "directory not empty")
246 _, err = rootFs.NewObject(context.Background(), "test/one")
247 require.NoError(t, err)
248 // validate that it exists in temp fs
249 _, err = os.Stat(path.Join(runInstance.tmpUploadDir, id, runInstance.encryptRemoteIfNeeded(t, "test/one")))
250 require.NoError(t, err)
251 started, err := boltDb.SearchPendingUpload(runInstance.encryptRemoteIfNeeded(t, path.Join(id, "test/one")))
252 require.False(t, started)
253 require.NoError(t, err)
254
255 // test Move/Rename -- allowed
256 err = runInstance.move(t, rootFs, path.Join("test", "one"), path.Join("test", "second"))
257 if err != errNotSupported {

Callers

nothing calls this directly

Calls 15

newCacheFsMethod · 0.80
JoinMethod · 0.80
PurgeTempUploadsMethod · 0.80
writeRemoteStringMethod · 0.80
readDataFromRemoteMethod · 0.80
encryptRemoteIfNeededMethod · 0.80
dirMoveMethod · 0.80
SearchPendingUploadMethod · 0.80
ContainsMethod · 0.80
readDataFromObjMethod · 0.80
StatMethod · 0.65
NewObjectMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…