2017-01-24 16:53:36 -05:00
|
|
|
package loader
|
|
|
|
|
|
|
|
import (
|
2017-05-09 19:21:17 -04:00
|
|
|
"fmt"
|
2017-01-24 16:53:36 -05:00
|
|
|
"testing"
|
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli/compose/types"
|
2017-08-21 16:39:35 -04:00
|
|
|
"github.com/docker/cli/internal/test/testutil"
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
"github.com/stretchr/testify/assert"
|
2017-01-24 16:53:36 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseVolumeAnonymousVolume(t *testing.T) {
|
|
|
|
for _, path := range []string{"/path", "/path/foo"} {
|
2017-05-09 19:21:17 -04:00
|
|
|
volume, err := ParseVolume(path)
|
2017-01-24 16:53:36 -05:00
|
|
|
expected := types.ServiceVolumeConfig{Type: "volume", Target: path}
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expected, volume)
|
2017-01-24 16:53:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseVolumeAnonymousVolumeWindows(t *testing.T) {
|
|
|
|
for _, path := range []string{"C:\\path", "Z:\\path\\foo"} {
|
2017-05-09 19:21:17 -04:00
|
|
|
volume, err := ParseVolume(path)
|
2017-01-24 16:53:36 -05:00
|
|
|
expected := types.ServiceVolumeConfig{Type: "volume", Target: path}
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expected, volume)
|
2017-01-24 16:53:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseVolumeTooManyColons(t *testing.T) {
|
2017-05-09 19:21:17 -04:00
|
|
|
_, err := ParseVolume("/foo:/foo:ro:foo")
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.EqualError(t, err, "invalid spec: /foo:/foo:ro:foo: too many colons")
|
2017-01-24 16:53:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseVolumeShortVolumes(t *testing.T) {
|
|
|
|
for _, path := range []string{".", "/a"} {
|
2017-05-09 19:21:17 -04:00
|
|
|
volume, err := ParseVolume(path)
|
2017-01-24 16:53:36 -05:00
|
|
|
expected := types.ServiceVolumeConfig{Type: "volume", Target: path}
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expected, volume)
|
2017-01-24 16:53:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseVolumeMissingSource(t *testing.T) {
|
|
|
|
for _, spec := range []string{":foo", "/foo::ro"} {
|
2017-05-09 19:21:17 -04:00
|
|
|
_, err := ParseVolume(spec)
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
testutil.ErrorContains(t, err, "empty section between colons")
|
2017-01-24 16:53:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseVolumeBindMount(t *testing.T) {
|
|
|
|
for _, path := range []string{"./foo", "~/thing", "../other", "/foo", "/home/user"} {
|
2017-05-09 19:21:17 -04:00
|
|
|
volume, err := ParseVolume(path + ":/target")
|
2017-01-24 16:53:36 -05:00
|
|
|
expected := types.ServiceVolumeConfig{
|
|
|
|
Type: "bind",
|
|
|
|
Source: path,
|
|
|
|
Target: "/target",
|
|
|
|
}
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expected, volume)
|
2017-01-24 16:53:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseVolumeRelativeBindMountWindows(t *testing.T) {
|
|
|
|
for _, path := range []string{
|
|
|
|
"./foo",
|
|
|
|
"~/thing",
|
|
|
|
"../other",
|
|
|
|
"D:\\path", "/home/user",
|
|
|
|
} {
|
2017-05-09 19:21:17 -04:00
|
|
|
volume, err := ParseVolume(path + ":d:\\target")
|
2017-01-24 16:53:36 -05:00
|
|
|
expected := types.ServiceVolumeConfig{
|
|
|
|
Type: "bind",
|
|
|
|
Source: path,
|
|
|
|
Target: "d:\\target",
|
|
|
|
}
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expected, volume)
|
2017-01-24 16:53:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseVolumeWithBindOptions(t *testing.T) {
|
2017-05-09 19:21:17 -04:00
|
|
|
volume, err := ParseVolume("/source:/target:slave")
|
2017-01-24 16:53:36 -05:00
|
|
|
expected := types.ServiceVolumeConfig{
|
|
|
|
Type: "bind",
|
|
|
|
Source: "/source",
|
|
|
|
Target: "/target",
|
|
|
|
Bind: &types.ServiceVolumeBind{Propagation: "slave"},
|
|
|
|
}
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expected, volume)
|
2017-01-24 16:53:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseVolumeWithBindOptionsWindows(t *testing.T) {
|
2017-05-09 19:21:17 -04:00
|
|
|
volume, err := ParseVolume("C:\\source\\foo:D:\\target:ro,rprivate")
|
2017-01-24 16:53:36 -05:00
|
|
|
expected := types.ServiceVolumeConfig{
|
|
|
|
Type: "bind",
|
|
|
|
Source: "C:\\source\\foo",
|
|
|
|
Target: "D:\\target",
|
|
|
|
ReadOnly: true,
|
|
|
|
Bind: &types.ServiceVolumeBind{Propagation: "rprivate"},
|
|
|
|
}
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expected, volume)
|
2017-01-24 16:53:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseVolumeWithInvalidVolumeOptions(t *testing.T) {
|
2017-05-09 19:21:17 -04:00
|
|
|
_, err := ParseVolume("name:/target:bogus")
|
|
|
|
assert.NoError(t, err)
|
2017-01-24 16:53:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseVolumeWithVolumeOptions(t *testing.T) {
|
2017-05-09 19:21:17 -04:00
|
|
|
volume, err := ParseVolume("name:/target:nocopy")
|
2017-01-24 16:53:36 -05:00
|
|
|
expected := types.ServiceVolumeConfig{
|
|
|
|
Type: "volume",
|
|
|
|
Source: "name",
|
|
|
|
Target: "/target",
|
|
|
|
Volume: &types.ServiceVolumeVolume{NoCopy: true},
|
|
|
|
}
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expected, volume)
|
2017-01-24 16:53:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseVolumeWithReadOnly(t *testing.T) {
|
|
|
|
for _, path := range []string{"./foo", "/home/user"} {
|
2017-05-09 19:21:17 -04:00
|
|
|
volume, err := ParseVolume(path + ":/target:ro")
|
2017-01-24 16:53:36 -05:00
|
|
|
expected := types.ServiceVolumeConfig{
|
|
|
|
Type: "bind",
|
|
|
|
Source: path,
|
|
|
|
Target: "/target",
|
|
|
|
ReadOnly: true,
|
|
|
|
}
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expected, volume)
|
2017-01-24 16:53:36 -05:00
|
|
|
}
|
|
|
|
}
|
2017-04-06 10:32:35 -04:00
|
|
|
|
|
|
|
func TestParseVolumeWithRW(t *testing.T) {
|
|
|
|
for _, path := range []string{"./foo", "/home/user"} {
|
2017-05-09 19:21:17 -04:00
|
|
|
volume, err := ParseVolume(path + ":/target:rw")
|
2017-04-06 10:32:35 -04:00
|
|
|
expected := types.ServiceVolumeConfig{
|
|
|
|
Type: "bind",
|
|
|
|
Source: path,
|
|
|
|
Target: "/target",
|
|
|
|
ReadOnly: false,
|
|
|
|
}
|
Remove pkg/testutil/assert in favor of testify
I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.
I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.
In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.
In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
2017-04-13 18:45:37 -04:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expected, volume)
|
2017-04-06 10:32:35 -04:00
|
|
|
}
|
|
|
|
}
|
2017-06-03 22:59:09 -04:00
|
|
|
|
|
|
|
func TestIsFilePath(t *testing.T) {
|
|
|
|
assert.False(t, isFilePath("a界"))
|
|
|
|
}
|
2017-05-09 19:21:17 -04:00
|
|
|
|
|
|
|
// Preserve the test cases for VolumeSplitN
|
|
|
|
func TestParseVolumeSplitCases(t *testing.T) {
|
|
|
|
for casenumber, x := range []struct {
|
|
|
|
input string
|
|
|
|
n int
|
|
|
|
expected []string
|
|
|
|
}{
|
|
|
|
{`C:\foo:d:`, -1, []string{`C:\foo`, `d:`}},
|
|
|
|
{`:C:\foo:d:`, -1, nil},
|
|
|
|
{`/foo:/bar:ro`, 3, []string{`/foo`, `/bar`, `ro`}},
|
|
|
|
{`/foo:/bar:ro`, 2, []string{`/foo`, `/bar:ro`}},
|
|
|
|
{`C:\foo\:/foo`, -1, []string{`C:\foo\`, `/foo`}},
|
|
|
|
{`d:\`, -1, []string{`d:\`}},
|
|
|
|
{`d:`, -1, []string{`d:`}},
|
|
|
|
{`d:\path`, -1, []string{`d:\path`}},
|
|
|
|
{`d:\path with space`, -1, []string{`d:\path with space`}},
|
|
|
|
{`d:\pathandmode:rw`, -1, []string{`d:\pathandmode`, `rw`}},
|
|
|
|
|
|
|
|
{`c:\:d:\`, -1, []string{`c:\`, `d:\`}},
|
|
|
|
{`c:\windows\:d:`, -1, []string{`c:\windows\`, `d:`}},
|
|
|
|
{`c:\windows:d:\s p a c e`, -1, []string{`c:\windows`, `d:\s p a c e`}},
|
|
|
|
{`c:\windows:d:\s p a c e:RW`, -1, []string{`c:\windows`, `d:\s p a c e`, `RW`}},
|
|
|
|
{`c:\program files:d:\s p a c e i n h o s t d i r`, -1, []string{`c:\program files`, `d:\s p a c e i n h o s t d i r`}},
|
|
|
|
{`0123456789name:d:`, -1, []string{`0123456789name`, `d:`}},
|
|
|
|
{`MiXeDcAsEnAmE:d:`, -1, []string{`MiXeDcAsEnAmE`, `d:`}},
|
|
|
|
{`name:D:`, -1, []string{`name`, `D:`}},
|
|
|
|
{`name:D::rW`, -1, []string{`name`, `D:`, `rW`}},
|
|
|
|
{`name:D::RW`, -1, []string{`name`, `D:`, `RW`}},
|
|
|
|
|
|
|
|
{`c:/:d:/forward/slashes/are/good/too`, -1, []string{`c:/`, `d:/forward/slashes/are/good/too`}},
|
|
|
|
{`c:\Windows`, -1, []string{`c:\Windows`}},
|
|
|
|
{`c:\Program Files (x86)`, -1, []string{`c:\Program Files (x86)`}},
|
|
|
|
{``, -1, nil},
|
|
|
|
{`.`, -1, []string{`.`}},
|
|
|
|
{`..\`, -1, []string{`..\`}},
|
|
|
|
{`c:\:..\`, -1, []string{`c:\`, `..\`}},
|
|
|
|
{`c:\:d:\:xyzzy`, -1, []string{`c:\`, `d:\`, `xyzzy`}},
|
|
|
|
// Cover directories with one-character name
|
|
|
|
{`/tmp/x/y:/foo/x/y`, -1, []string{`/tmp/x/y`, `/foo/x/y`}},
|
|
|
|
} {
|
|
|
|
parsed, _ := ParseVolume(x.input)
|
|
|
|
|
|
|
|
expected := len(x.expected) > 1
|
|
|
|
msg := fmt.Sprintf("Case %d: %s", casenumber, x.input)
|
|
|
|
assert.Equal(t, expected, parsed.Source != "", msg)
|
|
|
|
}
|
|
|
|
}
|
2017-05-09 18:35:25 -04:00
|
|
|
|
|
|
|
func TestParseVolumeInvalidEmptySpec(t *testing.T) {
|
|
|
|
_, err := ParseVolume("")
|
|
|
|
testutil.ErrorContains(t, err, "invalid empty volume spec")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseVolumeInvalidSections(t *testing.T) {
|
|
|
|
_, err := ParseVolume("/foo::rw")
|
|
|
|
testutil.ErrorContains(t, err, "invalid spec")
|
|
|
|
}
|