github.com/pkg/sftp@v1.13.6/server_windows_test.go (about) 1 package sftp 2 3 import ( 4 "testing" 5 ) 6 7 func TestServer_toLocalPath(t *testing.T) { 8 tests := []struct { 9 name string 10 withWorkDir string 11 p string 12 want string 13 }{ 14 { 15 name: "empty path with no workdir", 16 p: "", 17 want: "", 18 }, 19 { 20 name: "relative path with no workdir", 21 p: "file", 22 want: "file", 23 }, 24 { 25 name: "absolute path with no workdir", 26 p: "/file", 27 want: "\\file", 28 }, 29 { 30 name: "workdir and empty path", 31 withWorkDir: "C:\\Users\\User", 32 p: "", 33 want: "C:\\Users\\User", 34 }, 35 { 36 name: "workdir and relative path", 37 withWorkDir: "C:\\Users\\User", 38 p: "file", 39 want: "C:\\Users\\User\\file", 40 }, 41 { 42 name: "workdir and relative path with .", 43 withWorkDir: "C:\\Users\\User", 44 p: ".", 45 want: "C:\\Users\\User", 46 }, 47 { 48 name: "workdir and relative path with . and file", 49 withWorkDir: "C:\\Users\\User", 50 p: "./file", 51 want: "C:\\Users\\User\\file", 52 }, 53 { 54 name: "workdir and absolute path", 55 withWorkDir: "C:\\Users\\User", 56 p: "/C:/file", 57 want: "C:\\file", 58 }, 59 { 60 name: "workdir and non-unixy path prefixes workdir", 61 withWorkDir: "C:\\Users\\User", 62 p: "C:\\file", 63 // This may look like a bug but it is the result of passing 64 // invalid input (a non-unixy path) to the server. 65 want: "C:\\Users\\User\\C:\\file", 66 }, 67 } 68 for _, tt := range tests { 69 t.Run(tt.name, func(t *testing.T) { 70 // We don't need to initialize the Server further to test 71 // toLocalPath behavior. 72 s := &Server{} 73 if tt.withWorkDir != "" { 74 if err := WithServerWorkingDirectory(tt.withWorkDir)(s); err != nil { 75 t.Fatal(err) 76 } 77 } 78 79 if got := s.toLocalPath(tt.p); got != tt.want { 80 t.Errorf("Server.toLocalPath() = %q, want %q", got, tt.want) 81 } 82 }) 83 } 84 }