github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/backend/combine/combine_internal_test.go (about) 1 package combine 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestAdjustmentDo(t *testing.T) { 11 for _, test := range []struct { 12 root string 13 mountpoint string 14 in string 15 want string 16 wantErr error 17 }{ 18 { 19 root: "", 20 mountpoint: "mountpoint", 21 in: "path/to/file.txt", 22 want: "mountpoint/path/to/file.txt", 23 }, 24 { 25 root: "mountpoint", 26 mountpoint: "mountpoint", 27 in: "path/to/file.txt", 28 want: "path/to/file.txt", 29 }, 30 { 31 root: "mountpoint/path", 32 mountpoint: "mountpoint", 33 in: "path/to/file.txt", 34 want: "to/file.txt", 35 }, 36 { 37 root: "mountpoint/path", 38 mountpoint: "mountpoint", 39 in: "wrongpath/to/file.txt", 40 want: "", 41 wantErr: errNotUnderRoot, 42 }, 43 } { 44 what := fmt.Sprintf("%+v", test) 45 a := newAdjustment(test.root, test.mountpoint) 46 got, gotErr := a.do(test.in) 47 assert.Equal(t, test.wantErr, gotErr) 48 assert.Equal(t, test.want, got, what) 49 } 50 51 } 52 53 func TestAdjustmentUndo(t *testing.T) { 54 for _, test := range []struct { 55 root string 56 mountpoint string 57 in string 58 want string 59 wantErr error 60 }{ 61 { 62 root: "", 63 mountpoint: "mountpoint", 64 in: "mountpoint/path/to/file.txt", 65 want: "path/to/file.txt", 66 }, 67 { 68 root: "mountpoint", 69 mountpoint: "mountpoint", 70 in: "path/to/file.txt", 71 want: "path/to/file.txt", 72 }, 73 { 74 root: "mountpoint/path", 75 mountpoint: "mountpoint", 76 in: "to/file.txt", 77 want: "path/to/file.txt", 78 }, 79 { 80 root: "wrongmountpoint/path", 81 mountpoint: "mountpoint", 82 in: "to/file.txt", 83 want: "", 84 wantErr: errNotUnderRoot, 85 }, 86 } { 87 what := fmt.Sprintf("%+v", test) 88 a := newAdjustment(test.root, test.mountpoint) 89 got, gotErr := a.undo(test.in) 90 assert.Equal(t, test.wantErr, gotErr) 91 assert.Equal(t, test.want, got, what) 92 } 93 94 }