MCPcopy
hub / github.com/rclone/rclone / InternalTestVersions

Method InternalTestVersions

backend/s3/s3_internal_test.go:299–506  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

297}
298
299func (f *Fs) InternalTestVersions(t *testing.T) {
300 ctx := context.Background()
301
302 // Enable versioning for this bucket during this test
303 _, err := f.setGetVersioning(ctx, "Enabled")
304 if err != nil {
305 t.Skipf("Couldn't enable versioning: %v", err)
306 }
307 defer func() {
308 // Disable versioning for this bucket
309 _, err := f.setGetVersioning(ctx, "Suspended")
310 assert.NoError(t, err)
311 }()
312
313 // Small pause to make the LastModified different since AWS
314 // only seems to track them to 1 second granularity
315 time.Sleep(2 * time.Second)
316
317 // Create an object
318 const dirName = "versions"
319 const fileName = dirName + "/" + "test-versions.txt"
320 contents := random.String(100)
321 item := fstest.NewItem(fileName, contents, fstest.Time("2001-05-06T04:05:06.499999999Z"))
322 obj := fstests.PutTestContents(ctx, t, f, &item, contents, true)
323 defer func() {
324 assert.NoError(t, obj.Remove(ctx))
325 }()
326
327 // Small pause
328 time.Sleep(2 * time.Second)
329
330 // Remove it
331 assert.NoError(t, obj.Remove(ctx))
332
333 // Small pause to make the LastModified different since AWS only seems to track them to 1 second granularity
334 time.Sleep(2 * time.Second)
335
336 // And create it with different size and contents
337 newContents := random.String(101)
338 newItem := fstest.NewItem(fileName, newContents, fstest.Time("2002-05-06T04:05:06.499999999Z"))
339 newObj := fstests.PutTestContents(ctx, t, f, &newItem, newContents, true)
340
341 t.Run("Versions", func(t *testing.T) {
342 // Set --s3-versions for this test
343 f.opt.Versions = true
344 defer func() {
345 f.opt.Versions = false
346 }()
347
348 // Read the contents
349 entries, err := f.List(ctx, dirName)
350 require.NoError(t, err)
351 tests := 0
352 var fileNameVersion string
353 for _, entry := range entries {
354 t.Log(entry)
355 remote := entry.Remote()
356 if remote == fileName {

Callers

nothing calls this directly

Calls 15

setGetVersioningMethod · 0.95
ListMethod · 0.95
NewObjectMethod · 0.95
SizeMethod · 0.95
RemoteMethod · 0.95
shouldRetryMethod · 0.95
CleanUpHiddenMethod · 0.95
StringFunction · 0.92
NewItemFunction · 0.92
TimeFunction · 0.92
PutTestContentsFunction · 0.92
ReadObjectFunction · 0.92

Tested by

no test coverage detected