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)
| 83 | // Copy and :memory: which can Copy but not Move to makes sure that |
| 84 | // the resulting union can Move |
| 85 | func 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…