github.com/brahmaroutu/docker@v1.2.1-0.20160809185609-eb28dde01f16/pkg/system/path_windows_test.go (about) 1 // +build windows 2 3 package system 4 5 import "testing" 6 7 // TestCheckSystemDriveAndRemoveDriveLetter tests CheckSystemDriveAndRemoveDriveLetter 8 func TestCheckSystemDriveAndRemoveDriveLetter(t *testing.T) { 9 // Fails if not C drive. 10 path, err := CheckSystemDriveAndRemoveDriveLetter(`d:\`) 11 if err == nil || (err != nil && err.Error() != "The specified path is not on the system drive (C:)") { 12 t.Fatalf("Expected error for d:") 13 } 14 15 // Single character is unchanged 16 if path, err = CheckSystemDriveAndRemoveDriveLetter("z"); err != nil { 17 t.Fatalf("Single character should pass") 18 } 19 if path != "z" { 20 t.Fatalf("Single character should be unchanged") 21 } 22 23 // Two characters without colon is unchanged 24 if path, err = CheckSystemDriveAndRemoveDriveLetter("AB"); err != nil { 25 t.Fatalf("2 characters without colon should pass") 26 } 27 if path != "AB" { 28 t.Fatalf("2 characters without colon should be unchanged") 29 } 30 31 // Abs path without drive letter 32 if path, err = CheckSystemDriveAndRemoveDriveLetter(`\l`); err != nil { 33 t.Fatalf("abs path no drive letter should pass") 34 } 35 if path != `\l` { 36 t.Fatalf("abs path without drive letter should be unchanged") 37 } 38 39 // Abs path without drive letter, linux style 40 if path, err = CheckSystemDriveAndRemoveDriveLetter(`/l`); err != nil { 41 t.Fatalf("abs path no drive letter linux style should pass") 42 } 43 if path != `\l` { 44 t.Fatalf("abs path without drive letter linux failed %s", path) 45 } 46 47 // Drive-colon should be stripped 48 if path, err = CheckSystemDriveAndRemoveDriveLetter(`c:\`); err != nil { 49 t.Fatalf("An absolute path should pass") 50 } 51 if path != `\` { 52 t.Fatalf(`An absolute path should have been shortened to \ %s`, path) 53 } 54 55 // Verify with a linux-style path 56 if path, err = CheckSystemDriveAndRemoveDriveLetter(`c:/`); err != nil { 57 t.Fatalf("An absolute path should pass") 58 } 59 if path != `\` { 60 t.Fatalf(`A linux style absolute path should have been shortened to \ %s`, path) 61 } 62 63 // Failure on c: 64 if path, err = CheckSystemDriveAndRemoveDriveLetter(`c:`); err == nil { 65 t.Fatalf("c: should fail") 66 } 67 if err.Error() != `No relative path specified in "c:"` { 68 t.Fatalf(path, err) 69 } 70 71 // Failure on d: 72 if path, err = CheckSystemDriveAndRemoveDriveLetter(`d:`); err == nil { 73 t.Fatalf("c: should fail") 74 } 75 if err.Error() != `No relative path specified in "d:"` { 76 t.Fatalf(path, err) 77 } 78 }