github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/backend/seafile/seafile_internal_test.go (about) 1 package seafile 2 3 import ( 4 "path" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 type pathData struct { 11 configLibrary string // Library specified in the config 12 configRoot string // Root directory specified in the config 13 argumentPath string // Path given as an argument in the command line 14 expectedLibrary string 15 expectedPath string 16 } 17 18 // Test the method to split a library name and a path 19 // from a mix of configuration data and path command line argument 20 func TestSplitPath(t *testing.T) { 21 testData := []pathData{ 22 pathData{ 23 configLibrary: "", 24 configRoot: "", 25 argumentPath: "", 26 expectedLibrary: "", 27 expectedPath: "", 28 }, 29 pathData{ 30 configLibrary: "", 31 configRoot: "", 32 argumentPath: "Library", 33 expectedLibrary: "Library", 34 expectedPath: "", 35 }, 36 pathData{ 37 configLibrary: "", 38 configRoot: "", 39 argumentPath: path.Join("Library", "path", "to", "file"), 40 expectedLibrary: "Library", 41 expectedPath: path.Join("path", "to", "file"), 42 }, 43 pathData{ 44 configLibrary: "Library", 45 configRoot: "", 46 argumentPath: "", 47 expectedLibrary: "Library", 48 expectedPath: "", 49 }, 50 pathData{ 51 configLibrary: "Library", 52 configRoot: "", 53 argumentPath: "path", 54 expectedLibrary: "Library", 55 expectedPath: "path", 56 }, 57 pathData{ 58 configLibrary: "Library", 59 configRoot: "", 60 argumentPath: path.Join("path", "to", "file"), 61 expectedLibrary: "Library", 62 expectedPath: path.Join("path", "to", "file"), 63 }, 64 pathData{ 65 configLibrary: "Library", 66 configRoot: "root", 67 argumentPath: "", 68 expectedLibrary: "Library", 69 expectedPath: "root", 70 }, 71 pathData{ 72 configLibrary: "Library", 73 configRoot: path.Join("root", "path"), 74 argumentPath: "", 75 expectedLibrary: "Library", 76 expectedPath: path.Join("root", "path"), 77 }, 78 pathData{ 79 configLibrary: "Library", 80 configRoot: "root", 81 argumentPath: "path", 82 expectedLibrary: "Library", 83 expectedPath: path.Join("root", "path"), 84 }, 85 pathData{ 86 configLibrary: "Library", 87 configRoot: "root", 88 argumentPath: path.Join("path", "to", "file"), 89 expectedLibrary: "Library", 90 expectedPath: path.Join("root", "path", "to", "file"), 91 }, 92 pathData{ 93 configLibrary: "Library", 94 configRoot: path.Join("root", "path"), 95 argumentPath: path.Join("subpath", "to", "file"), 96 expectedLibrary: "Library", 97 expectedPath: path.Join("root", "path", "subpath", "to", "file"), 98 }, 99 } 100 for _, test := range testData { 101 fs := &Fs{ 102 libraryName: test.configLibrary, 103 rootDirectory: test.configRoot, 104 } 105 libraryName, path := fs.splitPath(test.argumentPath) 106 107 assert.Equal(t, test.expectedLibrary, libraryName) 108 assert.Equal(t, test.expectedPath, path) 109 } 110 } 111 112 func TestSplitPathIntoSlice(t *testing.T) { 113 testData := map[string][]string{ 114 "1": {"1"}, 115 "/1": {"1"}, 116 "/1/": {"1"}, 117 "1/2/3": {"1", "2", "3"}, 118 } 119 for input, expected := range testData { 120 output := splitPath(input) 121 assert.Equal(t, expected, output) 122 } 123 }