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

Method InternalTestVersions

backend/b2/b2_internal_test.go:309–489  ·  view source on GitHub ↗

This is adapted from the s3 equivalent.

(t *testing.T)

Source from the content-addressed store, hash-verified

307
308// This is adapted from the s3 equivalent.
309func (f *Fs) InternalTestVersions(t *testing.T) {
310 ctx := context.Background()
311
312 // Small pause to make the LastModified different since AWS
313 // only seems to track them to 1 second granularity
314 time.Sleep(2 * time.Second)
315
316 // Create an object
317 const dirName = "versions"
318 const fileName = dirName + "/" + "test-versions.txt"
319 contents := random.String(100)
320 item := fstest.NewItem(fileName, contents, fstest.Time("2001-05-06T04:05:06.499999999Z"))
321 obj := fstests.PutTestContents(ctx, t, f, &item, contents, true)
322 defer func() {
323 assert.NoError(t, obj.Remove(ctx))
324 }()
325 objMetadata, err := obj.(*Object).getMetaData(ctx)
326 require.NoError(t, err)
327
328 // Small pause
329 time.Sleep(2 * time.Second)
330
331 // Remove it
332 assert.NoError(t, obj.Remove(ctx))
333
334 // Small pause to make the LastModified different since AWS only seems to track them to 1 second granularity
335 time.Sleep(2 * time.Second)
336
337 // And create it with different size and contents
338 newContents := random.String(101)
339 newItem := fstest.NewItem(fileName, newContents, fstest.Time("2002-05-06T04:05:06.499999999Z"))
340 newObj := fstests.PutTestContents(ctx, t, f, &newItem, newContents, true)
341 newObjMetadata, err := newObj.(*Object).getMetaData(ctx)
342 require.NoError(t, err)
343
344 t.Run("Versions", func(t *testing.T) {
345 // Set --b2-versions for this test
346 f.opt.Versions = true
347 defer func() {
348 f.opt.Versions = false
349 }()
350
351 // Read the contents
352 entries, err := f.List(ctx, dirName)
353 require.NoError(t, err)
354 tests := 0
355 var fileNameVersion string
356 for _, entry := range entries {
357 t.Log(entry)
358 remote := entry.Remote()
359 if remote == fileName {
360 t.Run("ReadCurrent", func(t *testing.T) {
361 assert.Equal(t, newContents, fstests.ReadObject(ctx, t, entry.(fs.Object), -1))
362 })
363 tests++
364 } else if versionTime, p := version.Remove(remote); !versionTime.IsZero() && p == fileName {
365 t.Run("ReadVersion", func(t *testing.T) {
366 assert.Equal(t, contents, fstests.ReadObject(ctx, t, entry.(fs.Object), -1))

Callers

nothing calls this directly

Calls 15

ListMethod · 0.95
NewObjectMethod · 0.95
SizeMethod · 0.95
RemoteMethod · 0.95
cleanUpMethod · 0.95
StringFunction · 0.92
NewItemFunction · 0.92
TimeFunction · 0.92
PutTestContentsFunction · 0.92
ReadObjectFunction · 0.92
RemoveFunction · 0.92
JoinFunction · 0.92

Tested by

no test coverage detected