Signed-off-by: Daniel Nephin <dnephin@docker.com>
| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,54 +0,0 @@ |
| 1 |
-package stack |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "testing" |
|
| 5 |
- |
|
| 6 |
- composetypes "github.com/aanand/compose-file/types" |
|
| 7 |
- "github.com/docker/docker/api/types/mount" |
|
| 8 |
- "github.com/docker/docker/api/types/swarm" |
|
| 9 |
- "github.com/docker/docker/pkg/testutil/assert" |
|
| 10 |
-) |
|
| 11 |
- |
|
| 12 |
-func TestConvertVolumeToMountAnonymousVolume(t *testing.T) {
|
|
| 13 |
- stackVolumes := map[string]composetypes.VolumeConfig{}
|
|
| 14 |
- namespace := namespace{name: "foo"}
|
|
| 15 |
- expected := mount.Mount{
|
|
| 16 |
- Type: mount.TypeVolume, |
|
| 17 |
- Target: "/foo/bar", |
|
| 18 |
- } |
|
| 19 |
- mnt, err := convertVolumeToMount("/foo/bar", stackVolumes, namespace)
|
|
| 20 |
- assert.NilError(t, err) |
|
| 21 |
- assert.DeepEqual(t, mnt, expected) |
|
| 22 |
-} |
|
| 23 |
- |
|
| 24 |
-func TestConvertVolumeToMountInvalidFormat(t *testing.T) {
|
|
| 25 |
- namespace := namespace{name: "foo"}
|
|
| 26 |
- invalids := []string{"::", "::cc", ":bb:", "aa::", "aa::cc", "aa:bb:", " : : ", " : :cc", " :bb: ", "aa: : ", "aa: :cc", "aa:bb: "}
|
|
| 27 |
- for _, vol := range invalids {
|
|
| 28 |
- _, err := convertVolumeToMount(vol, map[string]composetypes.VolumeConfig{}, namespace)
|
|
| 29 |
- assert.Error(t, err, "invalid volume: "+vol) |
|
| 30 |
- } |
|
| 31 |
-} |
|
| 32 |
- |
|
| 33 |
-func TestConvertResourcesOnlyMemory(t *testing.T) {
|
|
| 34 |
- source := composetypes.Resources{
|
|
| 35 |
- Limits: &composetypes.Resource{
|
|
| 36 |
- MemoryBytes: composetypes.UnitBytes(300000000), |
|
| 37 |
- }, |
|
| 38 |
- Reservations: &composetypes.Resource{
|
|
| 39 |
- MemoryBytes: composetypes.UnitBytes(200000000), |
|
| 40 |
- }, |
|
| 41 |
- } |
|
| 42 |
- resources, err := convertResources(source) |
|
| 43 |
- assert.NilError(t, err) |
|
| 44 |
- |
|
| 45 |
- expected := &swarm.ResourceRequirements{
|
|
| 46 |
- Limits: &swarm.Resources{
|
|
| 47 |
- MemoryBytes: 300000000, |
|
| 48 |
- }, |
|
| 49 |
- Reservations: &swarm.Resources{
|
|
| 50 |
- MemoryBytes: 200000000, |
|
| 51 |
- }, |
|
| 52 |
- } |
|
| 53 |
- assert.DeepEqual(t, resources, expected) |
|
| 54 |
-} |
| ... | ... |
@@ -80,6 +80,29 @@ func TestConvertResourcesFull(t *testing.T) {
|
| 80 | 80 |
assert.DeepEqual(t, resources, expected) |
| 81 | 81 |
} |
| 82 | 82 |
|
| 83 |
+func TestConvertResourcesOnlyMemory(t *testing.T) {
|
|
| 84 |
+ source := composetypes.Resources{
|
|
| 85 |
+ Limits: &composetypes.Resource{
|
|
| 86 |
+ MemoryBytes: composetypes.UnitBytes(300000000), |
|
| 87 |
+ }, |
|
| 88 |
+ Reservations: &composetypes.Resource{
|
|
| 89 |
+ MemoryBytes: composetypes.UnitBytes(200000000), |
|
| 90 |
+ }, |
|
| 91 |
+ } |
|
| 92 |
+ resources, err := convertResources(source) |
|
| 93 |
+ assert.NilError(t, err) |
|
| 94 |
+ |
|
| 95 |
+ expected := &swarm.ResourceRequirements{
|
|
| 96 |
+ Limits: &swarm.Resources{
|
|
| 97 |
+ MemoryBytes: 300000000, |
|
| 98 |
+ }, |
|
| 99 |
+ Reservations: &swarm.Resources{
|
|
| 100 |
+ MemoryBytes: 200000000, |
|
| 101 |
+ }, |
|
| 102 |
+ } |
|
| 103 |
+ assert.DeepEqual(t, resources, expected) |
|
| 104 |
+} |
|
| 105 |
+ |
|
| 83 | 106 |
func TestConvertHealthcheck(t *testing.T) {
|
| 84 | 107 |
retries := uint64(10) |
| 85 | 108 |
source := &composetypes.HealthCheckConfig{
|
| ... | ... |
@@ -49,6 +49,14 @@ func convertVolumeToMount(volumeSpec string, stackVolumes volumes, namespace Nam |
| 49 | 49 |
target = parts[0] |
| 50 | 50 |
} |
| 51 | 51 |
|
| 52 |
+ if source == "" {
|
|
| 53 |
+ // Anonymous volume |
|
| 54 |
+ return mount.Mount{
|
|
| 55 |
+ Type: mount.TypeVolume, |
|
| 56 |
+ Target: target, |
|
| 57 |
+ }, nil |
|
| 58 |
+ } |
|
| 59 |
+ |
|
| 52 | 60 |
// TODO: catch Windows paths here |
| 53 | 61 |
if strings.HasPrefix(source, "/") {
|
| 54 | 62 |
return mount.Mount{
|
| ... | ... |
@@ -110,3 +110,24 @@ func TestConvertVolumeToMountVolumeDoesNotExist(t *testing.T) {
|
| 110 | 110 |
_, err := convertVolumeToMount("unknown:/foo:ro", volumes{}, namespace)
|
| 111 | 111 |
assert.Error(t, err, "undefined volume: unknown") |
| 112 | 112 |
} |
| 113 |
+ |
|
| 114 |
+func TestConvertVolumeToMountAnonymousVolume(t *testing.T) {
|
|
| 115 |
+ stackVolumes := map[string]composetypes.VolumeConfig{}
|
|
| 116 |
+ namespace := NewNamespace("foo")
|
|
| 117 |
+ expected := mount.Mount{
|
|
| 118 |
+ Type: mount.TypeVolume, |
|
| 119 |
+ Target: "/foo/bar", |
|
| 120 |
+ } |
|
| 121 |
+ mnt, err := convertVolumeToMount("/foo/bar", stackVolumes, namespace)
|
|
| 122 |
+ assert.NilError(t, err) |
|
| 123 |
+ assert.DeepEqual(t, mnt, expected) |
|
| 124 |
+} |
|
| 125 |
+ |
|
| 126 |
+func TestConvertVolumeToMountInvalidFormat(t *testing.T) {
|
|
| 127 |
+ namespace := NewNamespace("foo")
|
|
| 128 |
+ invalids := []string{"::", "::cc", ":bb:", "aa::", "aa::cc", "aa:bb:", " : : ", " : :cc", " :bb: ", "aa: : ", "aa: :cc", "aa:bb: "}
|
|
| 129 |
+ for _, vol := range invalids {
|
|
| 130 |
+ _, err := convertVolumeToMount(vol, map[string]composetypes.VolumeConfig{}, namespace)
|
|
| 131 |
+ assert.Error(t, err, "invalid volume: "+vol) |
|
| 132 |
+ } |
|
| 133 |
+} |