|
6 | 6 | "time" |
7 | 7 |
|
8 | 8 | "github.com/docker/docker/api/types/container" |
9 | | - mounttypes "github.com/docker/docker/api/types/mount" |
10 | 9 | "github.com/docker/docker/pkg/testutil/assert" |
11 | 10 | ) |
12 | 11 |
|
@@ -68,151 +67,6 @@ func TestUint64OptSetAndValue(t *testing.T) { |
68 | 67 | assert.Equal(t, *opt.Value(), uint64(14445)) |
69 | 68 | } |
70 | 69 |
|
71 | | -func TestMountOptString(t *testing.T) { |
72 | | - mount := MountOpt{ |
73 | | - values: []mounttypes.Mount{ |
74 | | - { |
75 | | - Type: mounttypes.TypeBind, |
76 | | - Source: "/home/path", |
77 | | - Target: "/target", |
78 | | - }, |
79 | | - { |
80 | | - Type: mounttypes.TypeVolume, |
81 | | - Source: "foo", |
82 | | - Target: "/target/foo", |
83 | | - }, |
84 | | - }, |
85 | | - } |
86 | | - expected := "bind /home/path /target, volume foo /target/foo" |
87 | | - assert.Equal(t, mount.String(), expected) |
88 | | -} |
89 | | - |
90 | | -func TestMountOptSetBindNoErrorBind(t *testing.T) { |
91 | | - for _, testcase := range []string{ |
92 | | - // tests several aliases that should have same result. |
93 | | - "type=bind,target=/target,source=/source", |
94 | | - "type=bind,src=/source,dst=/target", |
95 | | - "type=bind,source=/source,dst=/target", |
96 | | - "type=bind,src=/source,target=/target", |
97 | | - } { |
98 | | - var mount MountOpt |
99 | | - |
100 | | - assert.NilError(t, mount.Set(testcase)) |
101 | | - |
102 | | - mounts := mount.Value() |
103 | | - assert.Equal(t, len(mounts), 1) |
104 | | - assert.Equal(t, mounts[0], mounttypes.Mount{ |
105 | | - Type: mounttypes.TypeBind, |
106 | | - Source: "/source", |
107 | | - Target: "/target", |
108 | | - }) |
109 | | - } |
110 | | -} |
111 | | - |
112 | | -func TestMountOptSetVolumeNoError(t *testing.T) { |
113 | | - for _, testcase := range []string{ |
114 | | - // tests several aliases that should have same result. |
115 | | - "type=volume,target=/target,source=/source", |
116 | | - "type=volume,src=/source,dst=/target", |
117 | | - "type=volume,source=/source,dst=/target", |
118 | | - "type=volume,src=/source,target=/target", |
119 | | - } { |
120 | | - var mount MountOpt |
121 | | - |
122 | | - assert.NilError(t, mount.Set(testcase)) |
123 | | - |
124 | | - mounts := mount.Value() |
125 | | - assert.Equal(t, len(mounts), 1) |
126 | | - assert.Equal(t, mounts[0], mounttypes.Mount{ |
127 | | - Type: mounttypes.TypeVolume, |
128 | | - Source: "/source", |
129 | | - Target: "/target", |
130 | | - }) |
131 | | - } |
132 | | -} |
133 | | - |
134 | | -// TestMountOptDefaultType ensures that a mount without the type defaults to a |
135 | | -// volume mount. |
136 | | -func TestMountOptDefaultType(t *testing.T) { |
137 | | - var mount MountOpt |
138 | | - assert.NilError(t, mount.Set("target=/target,source=/foo")) |
139 | | - assert.Equal(t, mount.values[0].Type, mounttypes.TypeVolume) |
140 | | -} |
141 | | - |
142 | | -func TestMountOptSetErrorNoTarget(t *testing.T) { |
143 | | - var mount MountOpt |
144 | | - assert.Error(t, mount.Set("type=volume,source=/foo"), "target is required") |
145 | | -} |
146 | | - |
147 | | -func TestMountOptSetErrorInvalidKey(t *testing.T) { |
148 | | - var mount MountOpt |
149 | | - assert.Error(t, mount.Set("type=volume,bogus=foo"), "unexpected key 'bogus'") |
150 | | -} |
151 | | - |
152 | | -func TestMountOptSetErrorInvalidField(t *testing.T) { |
153 | | - var mount MountOpt |
154 | | - assert.Error(t, mount.Set("type=volume,bogus"), "invalid field 'bogus'") |
155 | | -} |
156 | | - |
157 | | -func TestMountOptSetErrorInvalidReadOnly(t *testing.T) { |
158 | | - var mount MountOpt |
159 | | - assert.Error(t, mount.Set("type=volume,readonly=no"), "invalid value for readonly: no") |
160 | | - assert.Error(t, mount.Set("type=volume,readonly=invalid"), "invalid value for readonly: invalid") |
161 | | -} |
162 | | - |
163 | | -func TestMountOptDefaultEnableReadOnly(t *testing.T) { |
164 | | - var m MountOpt |
165 | | - assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo")) |
166 | | - assert.Equal(t, m.values[0].ReadOnly, false) |
167 | | - |
168 | | - m = MountOpt{} |
169 | | - assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly")) |
170 | | - assert.Equal(t, m.values[0].ReadOnly, true) |
171 | | - |
172 | | - m = MountOpt{} |
173 | | - assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=1")) |
174 | | - assert.Equal(t, m.values[0].ReadOnly, true) |
175 | | - |
176 | | - m = MountOpt{} |
177 | | - assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=true")) |
178 | | - assert.Equal(t, m.values[0].ReadOnly, true) |
179 | | - |
180 | | - m = MountOpt{} |
181 | | - assert.NilError(t, m.Set("type=bind,target=/foo,source=/foo,readonly=0")) |
182 | | - assert.Equal(t, m.values[0].ReadOnly, false) |
183 | | -} |
184 | | - |
185 | | -func TestMountOptVolumeNoCopy(t *testing.T) { |
186 | | - var m MountOpt |
187 | | - assert.NilError(t, m.Set("type=volume,target=/foo,volume-nocopy")) |
188 | | - assert.Equal(t, m.values[0].Source, "") |
189 | | - |
190 | | - m = MountOpt{} |
191 | | - assert.NilError(t, m.Set("type=volume,target=/foo,source=foo")) |
192 | | - assert.Equal(t, m.values[0].VolumeOptions == nil, true) |
193 | | - |
194 | | - m = MountOpt{} |
195 | | - assert.NilError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy=true")) |
196 | | - assert.Equal(t, m.values[0].VolumeOptions != nil, true) |
197 | | - assert.Equal(t, m.values[0].VolumeOptions.NoCopy, true) |
198 | | - |
199 | | - m = MountOpt{} |
200 | | - assert.NilError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy")) |
201 | | - assert.Equal(t, m.values[0].VolumeOptions != nil, true) |
202 | | - assert.Equal(t, m.values[0].VolumeOptions.NoCopy, true) |
203 | | - |
204 | | - m = MountOpt{} |
205 | | - assert.NilError(t, m.Set("type=volume,target=/foo,source=foo,volume-nocopy=1")) |
206 | | - assert.Equal(t, m.values[0].VolumeOptions != nil, true) |
207 | | - assert.Equal(t, m.values[0].VolumeOptions.NoCopy, true) |
208 | | -} |
209 | | - |
210 | | -func TestMountOptTypeConflict(t *testing.T) { |
211 | | - var m MountOpt |
212 | | - assert.Error(t, m.Set("type=bind,target=/foo,source=/foo,volume-nocopy=true"), "cannot mix") |
213 | | - assert.Error(t, m.Set("type=volume,target=/foo,source=/foo,bind-propagation=rprivate"), "cannot mix") |
214 | | -} |
215 | | - |
216 | 70 | func TestHealthCheckOptionsToHealthConfig(t *testing.T) { |
217 | 71 | dur := time.Second |
218 | 72 | opt := healthCheckOptions{ |
|
0 commit comments