Fix some bad merges

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2017-01-25 16:43:02 -05:00
parent 5bf7901f5d
commit 6bc7bc19df
4 changed files with 52 additions and 54 deletions

View file

@ -1,54 +0,0 @@
package stack
import (
"testing"
composetypes "github.com/aanand/compose-file/types"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/pkg/testutil/assert"
)
func TestConvertVolumeToMountAnonymousVolume(t *testing.T) {
stackVolumes := map[string]composetypes.VolumeConfig{}
namespace := namespace{name: "foo"}
expected := mount.Mount{
Type: mount.TypeVolume,
Target: "/foo/bar",
}
mnt, err := convertVolumeToMount("/foo/bar", stackVolumes, namespace)
assert.NilError(t, err)
assert.DeepEqual(t, mnt, expected)
}
func TestConvertVolumeToMountInvalidFormat(t *testing.T) {
namespace := namespace{name: "foo"}
invalids := []string{"::", "::cc", ":bb:", "aa::", "aa::cc", "aa:bb:", " : : ", " : :cc", " :bb: ", "aa: : ", "aa: :cc", "aa:bb: "}
for _, vol := range invalids {
_, err := convertVolumeToMount(vol, map[string]composetypes.VolumeConfig{}, namespace)
assert.Error(t, err, "invalid volume: "+vol)
}
}
func TestConvertResourcesOnlyMemory(t *testing.T) {
source := composetypes.Resources{
Limits: &composetypes.Resource{
MemoryBytes: composetypes.UnitBytes(300000000),
},
Reservations: &composetypes.Resource{
MemoryBytes: composetypes.UnitBytes(200000000),
},
}
resources, err := convertResources(source)
assert.NilError(t, err)
expected := &swarm.ResourceRequirements{
Limits: &swarm.Resources{
MemoryBytes: 300000000,
},
Reservations: &swarm.Resources{
MemoryBytes: 200000000,
},
}
assert.DeepEqual(t, resources, expected)
}

View file

@ -80,6 +80,29 @@ func TestConvertResourcesFull(t *testing.T) {
assert.DeepEqual(t, resources, expected)
}
func TestConvertResourcesOnlyMemory(t *testing.T) {
source := composetypes.Resources{
Limits: &composetypes.Resource{
MemoryBytes: composetypes.UnitBytes(300000000),
},
Reservations: &composetypes.Resource{
MemoryBytes: composetypes.UnitBytes(200000000),
},
}
resources, err := convertResources(source)
assert.NilError(t, err)
expected := &swarm.ResourceRequirements{
Limits: &swarm.Resources{
MemoryBytes: 300000000,
},
Reservations: &swarm.Resources{
MemoryBytes: 200000000,
},
}
assert.DeepEqual(t, resources, expected)
}
func TestConvertHealthcheck(t *testing.T) {
retries := uint64(10)
source := &composetypes.HealthCheckConfig{

View file

@ -49,6 +49,14 @@ func convertVolumeToMount(volumeSpec string, stackVolumes volumes, namespace Nam
target = parts[0]
}
if source == "" {
// Anonymous volume
return mount.Mount{
Type: mount.TypeVolume,
Target: target,
}, nil
}
// TODO: catch Windows paths here
if strings.HasPrefix(source, "/") {
return mount.Mount{

View file

@ -110,3 +110,24 @@ func TestConvertVolumeToMountVolumeDoesNotExist(t *testing.T) {
_, err := convertVolumeToMount("unknown:/foo:ro", volumes{}, namespace)
assert.Error(t, err, "undefined volume: unknown")
}
func TestConvertVolumeToMountAnonymousVolume(t *testing.T) {
stackVolumes := map[string]composetypes.VolumeConfig{}
namespace := NewNamespace("foo")
expected := mount.Mount{
Type: mount.TypeVolume,
Target: "/foo/bar",
}
mnt, err := convertVolumeToMount("/foo/bar", stackVolumes, namespace)
assert.NilError(t, err)
assert.DeepEqual(t, mnt, expected)
}
func TestConvertVolumeToMountInvalidFormat(t *testing.T) {
namespace := NewNamespace("foo")
invalids := []string{"::", "::cc", ":bb:", "aa::", "aa::cc", "aa:bb:", " : : ", " : :cc", " :bb: ", "aa: : ", "aa: :cc", "aa:bb: "}
for _, vol := range invalids {
_, err := convertVolumeToMount(vol, map[string]composetypes.VolumeConfig{}, namespace)
assert.Error(t, err, "invalid volume: "+vol)
}
}