2019-01-11 13:28:40 +00:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestExpandPath(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
base string
|
|
|
|
target string
|
|
|
|
expected string
|
|
|
|
}{
|
|
|
|
{"/tmp/alloc/task", ".", "/tmp/alloc/task"},
|
|
|
|
{"/tmp/alloc/task", "..", "/tmp/alloc"},
|
|
|
|
|
|
|
|
{"/tmp/alloc/task", "d1/d2", "/tmp/alloc/task/d1/d2"},
|
|
|
|
{"/tmp/alloc/task", "../d1/d2", "/tmp/alloc/d1/d2"},
|
|
|
|
{"/tmp/alloc/task", "../../d1/d2", "/tmp/d1/d2"},
|
|
|
|
|
|
|
|
{"/tmp/alloc/task", "c:/home/user", "c:/home/user"},
|
|
|
|
{"/tmp/alloc/task", "c:/home/user/..", "c:/home"},
|
2020-03-03 13:00:19 +00:00
|
|
|
|
|
|
|
{"/tmp/alloc/task", `//./pipe/named_pipe`, `//./pipe/named_pipe`},
|
2019-01-11 13:28:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range cases {
|
|
|
|
t.Run(c.expected, func(t *testing.T) {
|
|
|
|
require.Equal(t, c.expected, filepath.ToSlash(expandPath(c.base, c.target)))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2019-02-25 02:35:51 +00:00
|
|
|
|
|
|
|
func TestParseVolumeSpec_Windows(t *testing.T) {
|
|
|
|
validCases := []struct {
|
|
|
|
name string
|
|
|
|
bindSpec string
|
|
|
|
hostPath string
|
|
|
|
containerPath string
|
|
|
|
mode string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"basic mount",
|
|
|
|
`c:\windows:e:\containerpath`,
|
|
|
|
`c:\windows`,
|
|
|
|
`e:\containerpath`,
|
|
|
|
"",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"relative path",
|
|
|
|
`relativepath:e:\containerpath`,
|
|
|
|
`relativepath`,
|
|
|
|
`e:\containerpath`,
|
|
|
|
"",
|
|
|
|
},
|
2020-03-03 13:00:19 +00:00
|
|
|
{
|
|
|
|
"named pipe",
|
|
|
|
`//./pipe/named_pipe://./pipe/named_pipe`,
|
|
|
|
`\\.\pipe\named_pipe`,
|
|
|
|
`//./pipe/named_pipe`,
|
|
|
|
"",
|
|
|
|
},
|
2019-02-25 02:35:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range validCases {
|
|
|
|
t.Run("valid:"+c.name, func(t *testing.T) {
|
|
|
|
hp, cp, m, err := parseVolumeSpec(c.bindSpec, "windows")
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, c.hostPath, hp)
|
|
|
|
require.Equal(t, c.containerPath, cp)
|
|
|
|
require.Equal(t, c.mode, m)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
invalidCases := []string{
|
|
|
|
// linux path
|
|
|
|
"/linux-path",
|
|
|
|
// windows single path entry
|
|
|
|
`e:\containerpath`,
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range invalidCases {
|
|
|
|
t.Run("invalid:"+c, func(t *testing.T) {
|
|
|
|
hp, cp, m, err := parseVolumeSpec(c, "windows")
|
|
|
|
require.Errorf(t, err, "expected error but parsed as %s:%s:%s", hp, cp, m)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|