MCPcopy
hub / github.com/rclone/rclone / TestInternalReadOnly

Method TestInternalReadOnly

backend/union/union_internal_test.go:30–74  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28}
29
30func (f *Fs) TestInternalReadOnly(t *testing.T) {
31 if f.name != "TestUnionRO" {
32 t.Skip("Only on RO union")
33 }
34 dir := "TestInternalReadOnly"
35 ctx := context.Background()
36 rofs := f.upstreams[len(f.upstreams)-1]
37 assert.False(t, rofs.IsWritable())
38
39 // Put a file onto the read only fs
40 contents := random.String(50)
41 file1 := fstest.NewItem(dir+"/file.txt", contents, time.Now())
42 obj1 := fstests.PutTestContents(ctx, t, rofs, &file1, contents, true)
43
44 // Check read from readonly fs via union
45 o, err := f.NewObject(ctx, file1.Path)
46 require.NoError(t, err)
47 assert.Equal(t, int64(50), o.Size())
48
49 // Now call Update on the union Object with new data
50 contents2 := random.String(100)
51 file2 := fstest.NewItem(dir+"/file.txt", contents2, time.Now())
52 in := bytes.NewBufferString(contents2)
53 src := object.NewStaticObjectInfo(file2.Path, file2.ModTime, file2.Size, true, nil, nil)
54 err = o.Update(ctx, in, src)
55 require.NoError(t, err)
56 assert.Equal(t, int64(100), o.Size())
57
58 // Check we read the new object via the union
59 o, err = f.NewObject(ctx, file1.Path)
60 require.NoError(t, err)
61 assert.Equal(t, int64(100), o.Size())
62
63 // Remove the object
64 assert.NoError(t, o.Remove(ctx))
65
66 // Check we read the old object in the read only layer now
67 o, err = f.NewObject(ctx, file1.Path)
68 require.NoError(t, err)
69 assert.Equal(t, int64(50), o.Size())
70
71 // Remove file and dir from read only fs
72 assert.NoError(t, obj1.Remove(ctx))
73 assert.NoError(t, rofs.Rmdir(ctx, dir))
74}
75
76func (f *Fs) InternalTest(t *testing.T) {
77 t.Run("ReadOnly", f.TestInternalReadOnly)

Callers

nothing calls this directly

Calls 12

NewObjectMethod · 0.95
SizeMethod · 0.95
UpdateMethod · 0.95
RemoveMethod · 0.95
StringFunction · 0.92
NewItemFunction · 0.92
PutTestContentsFunction · 0.92
NewStaticObjectInfoFunction · 0.92
IsWritableMethod · 0.80
RemoveMethod · 0.65
RmdirMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected