github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/drivers/docker/utils_windows_test.go (about) 1 // +build windows 2 3 package docker 4 5 import ( 6 "path/filepath" 7 "testing" 8 9 "github.com/stretchr/testify/require" 10 ) 11 12 func TestExpandPath(t *testing.T) { 13 cases := []struct { 14 base string 15 target string 16 expected string 17 }{ 18 {"/tmp/alloc/task", ".", "/tmp/alloc/task"}, 19 {"/tmp/alloc/task", "..", "/tmp/alloc"}, 20 21 {"/tmp/alloc/task", "d1/d2", "/tmp/alloc/task/d1/d2"}, 22 {"/tmp/alloc/task", "../d1/d2", "/tmp/alloc/d1/d2"}, 23 {"/tmp/alloc/task", "../../d1/d2", "/tmp/d1/d2"}, 24 25 {"/tmp/alloc/task", "c:/home/user", "c:/home/user"}, 26 {"/tmp/alloc/task", "c:/home/user/..", "c:/home"}, 27 28 {"/tmp/alloc/task", `//./pipe/named_pipe`, `//./pipe/named_pipe`}, 29 } 30 31 for _, c := range cases { 32 t.Run(c.expected, func(t *testing.T) { 33 require.Equal(t, c.expected, filepath.ToSlash(expandPath(c.base, c.target))) 34 }) 35 } 36 } 37 38 func TestParseVolumeSpec_Windows(t *testing.T) { 39 validCases := []struct { 40 name string 41 bindSpec string 42 hostPath string 43 containerPath string 44 mode string 45 }{ 46 { 47 "basic mount", 48 `c:\windows:e:\containerpath`, 49 `c:\windows`, 50 `e:\containerpath`, 51 "", 52 }, 53 { 54 "relative path", 55 `relativepath:e:\containerpath`, 56 `relativepath`, 57 `e:\containerpath`, 58 "", 59 }, 60 { 61 "named pipe", 62 `//./pipe/named_pipe://./pipe/named_pipe`, 63 `\\.\pipe\named_pipe`, 64 `//./pipe/named_pipe`, 65 "", 66 }, 67 } 68 69 for _, c := range validCases { 70 t.Run("valid:"+c.name, func(t *testing.T) { 71 hp, cp, m, err := parseVolumeSpec(c.bindSpec, "windows") 72 require.NoError(t, err) 73 require.Equal(t, c.hostPath, hp) 74 require.Equal(t, c.containerPath, cp) 75 require.Equal(t, c.mode, m) 76 }) 77 } 78 79 invalidCases := []string{ 80 // linux path 81 "/linux-path", 82 // windows single path entry 83 `e:\containerpath`, 84 } 85 86 for _, c := range invalidCases { 87 t.Run("invalid:"+c, func(t *testing.T) { 88 hp, cp, m, err := parseVolumeSpec(c, "windows") 89 require.Errorf(t, err, "expected error but parsed as %s:%s:%s", hp, cp, m) 90 }) 91 } 92 }