MCPcopy
hub / github.com/rclone/rclone / TestMoveCopy

Function TestMoveCopy

backend/union/union_internal_test.go:85–165  ·  view source on GitHub ↗

This specifically tests a union of local which can Move but not Copy and :memory: which can Copy but not Move to makes sure that the resulting union can Move

(t *testing.T)

Source from the content-addressed store, hash-verified

83// Copy and :memory: which can Copy but not Move to makes sure that
84// the resulting union can Move
85func TestMoveCopy(t *testing.T) {
86 if *fstest.RemoteName != "" {
87 t.Skip("Skipping as -remote set")
88 }
89 ctx := context.Background()
90 dirs := MakeTestDirs(t, 1)
91 fsString := fmt.Sprintf(":union,upstreams='%s :memory:bucket':", dirs[0])
92 f, err := fs.NewFs(ctx, fsString)
93 require.NoError(t, err)
94
95 unionFs := f.(*Fs)
96 fLocal := unionFs.upstreams[0].Fs
97 fMemory := unionFs.upstreams[1].Fs
98
99 if runtime.GOOS == "darwin" {
100 // need to disable as this test specifically tests a local that can't Copy
101 f.Features().Disable("Copy")
102 fLocal.Features().Disable("Copy")
103 }
104
105 t.Run("Features", func(t *testing.T) {
106 assert.NotNil(t, f.Features().Move)
107 assert.Nil(t, f.Features().Copy)
108
109 // Check underlying are as we are expect
110 assert.NotNil(t, fLocal.Features().Move)
111 assert.Nil(t, fLocal.Features().Copy)
112 assert.Nil(t, fMemory.Features().Move)
113 assert.NotNil(t, fMemory.Features().Copy)
114 })
115
116 // Put a file onto the local fs
117 contentsLocal := random.String(50)
118 fileLocal := fstest.NewItem("local.txt", contentsLocal, time.Now())
119 _ = fstests.PutTestContents(ctx, t, fLocal, &fileLocal, contentsLocal, true)
120 objLocal, err := f.NewObject(ctx, fileLocal.Path)
121 require.NoError(t, err)
122
123 // Put a file onto the memory fs
124 contentsMemory := random.String(60)
125 fileMemory := fstest.NewItem("memory.txt", contentsMemory, time.Now())
126 _ = fstests.PutTestContents(ctx, t, fMemory, &fileMemory, contentsMemory, true)
127 objMemory, err := f.NewObject(ctx, fileMemory.Path)
128 require.NoError(t, err)
129
130 fstest.CheckListing(t, f, []fstest.Item{fileLocal, fileMemory})
131
132 t.Run("MoveLocal", func(t *testing.T) {
133 fileLocal.Path = "local-renamed.txt"
134 _, err := operations.Move(ctx, f, nil, fileLocal.Path, objLocal)
135 require.NoError(t, err)
136 fstest.CheckListing(t, f, []fstest.Item{fileLocal, fileMemory})
137
138 // Check can retrieve object from union
139 obj, err := f.NewObject(ctx, fileLocal.Path)
140 require.NoError(t, err)
141 assert.Equal(t, fileLocal.Size, obj.Size())
142

Callers

nothing calls this directly

Calls 15

FeaturesMethod · 0.95
NewObjectMethod · 0.95
SizeMethod · 0.95
NewFsFunction · 0.92
StringFunction · 0.92
NewItemFunction · 0.92
PutTestContentsFunction · 0.92
CheckListingFunction · 0.92
MoveFunction · 0.92
DisableMethod · 0.80
MakeTestDirsFunction · 0.70
FeaturesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…