Skip to content

Commit 540f7f0

Browse files
committed
opts: MountOpt: add test-coverage for volume options
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent c45767f commit 540f7f0

File tree

1 file changed

+175
-0
lines changed

1 file changed

+175
-0
lines changed

opts/mount_test.go

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,181 @@ func TestMountOptVolumeNoCopy(t *testing.T) {
254254
}
255255
}
256256

257+
func TestMountOptVolumeOptions(t *testing.T) {
258+
tests := []struct {
259+
doc string
260+
value string
261+
exp mount.Mount
262+
}{
263+
{
264+
doc: "volume-label single",
265+
value: `type=volume,target=/foo,volume-label=foo=foo-value`,
266+
exp: mount.Mount{
267+
Type: mount.TypeVolume,
268+
Target: "/foo",
269+
VolumeOptions: &mount.VolumeOptions{
270+
Labels: map[string]string{
271+
"foo": "foo-value",
272+
},
273+
DriverConfig: &mount.Driver{},
274+
},
275+
},
276+
},
277+
{
278+
doc: "volume-label multiple",
279+
value: `type=volume,target=/foo,volume-label=foo=foo-value,volume-label=bar=bar-value`,
280+
exp: mount.Mount{
281+
Type: mount.TypeVolume,
282+
Target: "/foo",
283+
VolumeOptions: &mount.VolumeOptions{
284+
Labels: map[string]string{
285+
"foo": "foo-value",
286+
"bar": "bar-value",
287+
},
288+
DriverConfig: &mount.Driver{},
289+
},
290+
},
291+
},
292+
{
293+
doc: "volume-label empty values",
294+
value: `type=volume,target=/foo,volume-label=foo=,volume-label=bar`,
295+
exp: mount.Mount{
296+
Type: mount.TypeVolume,
297+
Target: "/foo",
298+
VolumeOptions: &mount.VolumeOptions{
299+
Labels: map[string]string{
300+
"foo": "",
301+
"bar": "",
302+
},
303+
DriverConfig: &mount.Driver{},
304+
},
305+
},
306+
},
307+
{
308+
// TODO(thaJeztah): this should probably be an error instead
309+
doc: "volume-label empty key",
310+
value: `type=volume,target=/foo,volume-label==foo-value`,
311+
exp: mount.Mount{
312+
Type: mount.TypeVolume,
313+
Target: "/foo",
314+
VolumeOptions: &mount.VolumeOptions{
315+
Labels: map[string]string{},
316+
DriverConfig: &mount.Driver{},
317+
},
318+
},
319+
},
320+
{
321+
doc: "volume-driver",
322+
value: `type=volume,target=/foo,volume-driver=my-driver`,
323+
exp: mount.Mount{
324+
Type: mount.TypeVolume,
325+
Target: "/foo",
326+
VolumeOptions: &mount.VolumeOptions{
327+
Labels: map[string]string{},
328+
DriverConfig: &mount.Driver{
329+
Name: "my-driver",
330+
},
331+
},
332+
},
333+
},
334+
{
335+
doc: "volume-opt single",
336+
value: `type=volume,target=/foo,volume-opt=foo=foo-value`,
337+
exp: mount.Mount{
338+
Type: mount.TypeVolume,
339+
Target: "/foo",
340+
VolumeOptions: &mount.VolumeOptions{
341+
Labels: map[string]string{},
342+
DriverConfig: &mount.Driver{
343+
Options: map[string]string{
344+
"foo": "foo-value",
345+
},
346+
},
347+
},
348+
},
349+
},
350+
{
351+
doc: "volume-opt multiple",
352+
value: `type=volume,target=/foo,volume-opt=foo=foo-value,volume-opt=bar=bar-value`,
353+
exp: mount.Mount{
354+
Type: mount.TypeVolume,
355+
Target: "/foo",
356+
VolumeOptions: &mount.VolumeOptions{
357+
Labels: map[string]string{},
358+
DriverConfig: &mount.Driver{
359+
Options: map[string]string{
360+
"foo": "foo-value",
361+
"bar": "bar-value",
362+
},
363+
},
364+
},
365+
},
366+
},
367+
{
368+
doc: "volume-opt empty values",
369+
value: `type=volume,target=/foo,volume-opt=foo=,volume-opt=bar`,
370+
exp: mount.Mount{
371+
Type: mount.TypeVolume,
372+
Target: "/foo",
373+
VolumeOptions: &mount.VolumeOptions{
374+
Labels: map[string]string{},
375+
DriverConfig: &mount.Driver{
376+
Options: map[string]string{
377+
"foo": "",
378+
"bar": "",
379+
},
380+
},
381+
},
382+
},
383+
},
384+
{
385+
// TODO(thaJeztah): this should probably be an error instead
386+
doc: "volume-opt empty key",
387+
value: `type=volume,target=/foo,volume-opt==foo-value`,
388+
exp: mount.Mount{
389+
Type: mount.TypeVolume,
390+
Target: "/foo",
391+
VolumeOptions: &mount.VolumeOptions{
392+
Labels: map[string]string{},
393+
DriverConfig: &mount.Driver{
394+
Options: map[string]string{},
395+
},
396+
},
397+
},
398+
},
399+
{
400+
doc: "volume-label and volume-opt",
401+
value: `type=volume,volume-driver=my-driver,target=/foo,volume-label=foo=foo-value,volume-label=empty=,volume-opt=foo=foo-value,volume-opt=empty=`,
402+
exp: mount.Mount{
403+
Type: mount.TypeVolume,
404+
Target: "/foo",
405+
VolumeOptions: &mount.VolumeOptions{
406+
Labels: map[string]string{
407+
"foo": "foo-value",
408+
"empty": "",
409+
},
410+
DriverConfig: &mount.Driver{
411+
Name: "my-driver",
412+
Options: map[string]string{
413+
"foo": "foo-value",
414+
"empty": "",
415+
},
416+
},
417+
},
418+
},
419+
},
420+
}
421+
422+
for _, tc := range tests {
423+
t.Run(tc.doc, func(t *testing.T) {
424+
var m MountOpt
425+
426+
assert.NilError(t, m.Set(tc.value))
427+
assert.Check(t, is.DeepEqual(m.values[0], tc.exp))
428+
})
429+
}
430+
}
431+
257432
func TestMountOptSetImageNoError(t *testing.T) {
258433
for _, tc := range []string{
259434
"type=image,source=foo,target=/target,image-subpath=/bar",

0 commit comments

Comments
 (0)