2017-01-24 16:53:36 -05:00
|
|
|
package loader
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2017-04-17 18:07:56 -04:00
|
|
|
"github.com/docker/cli/cli/compose/types"
|
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/docker/docker/pkg/testutil"
|
|
|
|
"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"} {
|
|
|
|
volume, err := parseVolume(path)
|
|
|
|
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"} {
|
|
|
|
volume, err := parseVolume(path)
|
|
|
|
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) {
|
|
|
|
_, 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"} {
|
|
|
|
volume, err := parseVolume(path)
|
|
|
|
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"} {
|
|
|
|
_, 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"} {
|
|
|
|
volume, err := parseVolume(path + ":/target")
|
|
|
|
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",
|
|
|
|
} {
|
|
|
|
volume, err := parseVolume(path + ":d:\\target")
|
|
|
|
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) {
|
|
|
|
volume, err := parseVolume("/source:/target:slave")
|
|
|
|
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) {
|
|
|
|
volume, err := parseVolume("C:\\source\\foo:D:\\target:ro,rprivate")
|
|
|
|
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) {
|
|
|
|
_, err := parseVolume("name:/target:bogus")
|
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: name:/target:bogus: unknown option: bogus")
|
2017-01-24 16:53:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseVolumeWithVolumeOptions(t *testing.T) {
|
|
|
|
volume, err := parseVolume("name:/target:nocopy")
|
|
|
|
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"} {
|
|
|
|
volume, err := parseVolume(path + ":/target:ro")
|
|
|
|
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"} {
|
|
|
|
volume, err := parseVolume(path + ":/target:rw")
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|