github.com/auxten/ginkgo@v0.0.0-20220130172820-7d98ad59d232/srcdest/srcdest_test.go (about) 1 package srcdest 2 3 import ( 4 "fmt" 5 "testing" 6 ) 7 8 func TestName(t *testing.T) { 9 var testData = []struct { 10 cSrc, cDest string 11 cSrcType, cDestType PathType 12 src, dest string 13 }{ 14 {"./src", "./dest", FileType, NotExist, "./src", "dest"}, 15 {"./src", "./dest", FileType, FileType, "./src", "dest"}, 16 {"./src", "./dest", FileType, DirType, "./src", "dest/src"}, 17 {"./src", "./dest/", FileType, NotExist, "./src", ""}, //error 18 {"./src", "./dest/", FileType, FileType, "./src", ""}, //error 19 {"./src", "./dest/", FileType, DirType, "./src", "dest/src"}, 20 {"./src", "./dest", DirType, NotExist, "./src/file", "dest/file"}, 21 {"./src", "./dest", DirType, FileType, "./src/file", ""}, //error 22 {"./src", "./dest", DirType, DirType, "./src/file", "dest/src/file"}, 23 {"./src", "./dest/", DirType, NotExist, "./src/file", "dest/file"}, 24 {"./src", "./dest/", DirType, FileType, "./src/file", ""}, //error 25 {"./src", "./dest/", DirType, DirType, "./src/file", "dest/src/file"}, 26 // Long path cases 27 {"./srcDir/src", "./destDir/dest", FileType, NotExist, "./srcDir/src", "destDir/dest"}, 28 {"./src", "./dest", DirType, NotExist, "./src/srcDir/file", "dest/srcDir/file"}, 29 {"./src", "./xxx/../dest", DirType, NotExist, "./src/srcDir/file", "dest/srcDir/file"}, 30 {"./src", "./destDir/dest", DirType, NotExist, "./src/srcDir/file", "destDir/dest/srcDir/file"}, 31 // Other error cases 32 {"./src", "", FileType, DirType, "./notSrc", ""}, 33 } 34 for i, d := range testData { 35 t.Run(fmt.Sprintf("test path normalization %d", i), func(t *testing.T) { 36 path, _ := NormalizeDestPath(d.cSrc, d.cDest, d.cSrcType, d.cDestType, d.src) 37 if path != d.dest { 38 t.Errorf("expect: %s, got: %s", d.dest, path) 39 } 40 }) 41 } 42 43 }