(t *testing.T)
| 28 | } |
| 29 | |
| 30 | func (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 | |
| 76 | func (f *Fs) InternalTest(t *testing.T) { |
| 77 | t.Run("ReadOnly", f.TestInternalReadOnly) |
nothing calls this directly
no test coverage detected