@@ -9,6 +9,55 @@ import (
99 is "gotest.tools/v3/assert/cmp"
1010)
1111
12+ func TestVolumesWithMultipleServiceVolumeConfigs (t * testing.T ) {
13+ namespace := NewNamespace ("foo" )
14+
15+ serviceVolumes := []composetypes.ServiceVolumeConfig {
16+ {
17+ Type : "volume" ,
18+ Target : "/foo" ,
19+ },
20+ {
21+ Type : "volume" ,
22+ Target : "/foo/bar" ,
23+ },
24+ }
25+
26+ expected := []mount.Mount {
27+ {
28+ Type : "volume" ,
29+ Target : "/foo" ,
30+ },
31+ {
32+ Type : "volume" ,
33+ Target : "/foo/bar" ,
34+ },
35+ }
36+
37+ mnt , err := Volumes (serviceVolumes , volumes {}, namespace )
38+ assert .NilError (t , err )
39+ assert .Check (t , is .DeepEqual (expected , mnt ))
40+ }
41+
42+ func TestVolumesWithMultipleServiceVolumeConfigsWithUndefinedVolumeConfig (t * testing.T ) {
43+ namespace := NewNamespace ("foo" )
44+
45+ serviceVolumes := []composetypes.ServiceVolumeConfig {
46+ {
47+ Type : "volume" ,
48+ Source : "foo" ,
49+ Target : "/foo" ,
50+ },
51+ {
52+ Type : "volume" ,
53+ Target : "/foo/bar" ,
54+ },
55+ }
56+
57+ _ , err := Volumes (serviceVolumes , volumes {}, namespace )
58+ assert .Error (t , err , "undefined volume \" foo\" " )
59+ }
60+
1261func TestConvertVolumeToMountAnonymousVolume (t * testing.T ) {
1362 config := composetypes.ServiceVolumeConfig {
1463 Type : "volume" ,
@@ -104,6 +153,49 @@ func TestConvertVolumeToMountConflictingOptionsTmpfsInBind(t *testing.T) {
104153 assert .Error (t , err , "tmpfs options are incompatible with type bind" )
105154}
106155
156+ func TestConvertVolumeToMountConflictingOptionsClusterInVolume (t * testing.T ) {
157+ namespace := NewNamespace ("foo" )
158+
159+ config := composetypes.ServiceVolumeConfig {
160+ Type : "volume" ,
161+ Target : "/target" ,
162+ Cluster : & composetypes.ServiceVolumeCluster {},
163+ }
164+ _ , err := convertVolumeToMount (config , volumes {}, namespace )
165+ assert .Error (t , err , "cluster options are incompatible with type volume" )
166+ }
167+
168+ func TestConvertVolumeToMountConflictingOptionsClusterInBind (t * testing.T ) {
169+ namespace := NewNamespace ("foo" )
170+
171+ config := composetypes.ServiceVolumeConfig {
172+ Type : "bind" ,
173+ Source : "/foo" ,
174+ Target : "/target" ,
175+ Bind : & composetypes.ServiceVolumeBind {
176+ Propagation : "slave" ,
177+ },
178+ Cluster : & composetypes.ServiceVolumeCluster {},
179+ }
180+ _ , err := convertVolumeToMount (config , volumes {}, namespace )
181+ assert .Error (t , err , "cluster options are incompatible with type bind" )
182+ }
183+
184+ func TestConvertVolumeToMountConflictingOptionsClusterInTmpfs (t * testing.T ) {
185+ namespace := NewNamespace ("foo" )
186+
187+ config := composetypes.ServiceVolumeConfig {
188+ Type : "tmpfs" ,
189+ Target : "/target" ,
190+ Tmpfs : & composetypes.ServiceVolumeTmpfs {
191+ Size : 1000 ,
192+ },
193+ Cluster : & composetypes.ServiceVolumeCluster {},
194+ }
195+ _ , err := convertVolumeToMount (config , volumes {}, namespace )
196+ assert .Error (t , err , "cluster options are incompatible with type tmpfs" )
197+ }
198+
107199func TestConvertVolumeToMountConflictingOptionsBindInTmpfs (t * testing.T ) {
108200 namespace := NewNamespace ("foo" )
109201
@@ -132,6 +224,50 @@ func TestConvertVolumeToMountConflictingOptionsVolumeInTmpfs(t *testing.T) {
132224 assert .Error (t , err , "volume options are incompatible with type tmpfs" )
133225}
134226
227+ func TestHandleNpipeToMountAnonymousNpipe (t * testing.T ) {
228+ namespace := NewNamespace ("foo" )
229+
230+ config := composetypes.ServiceVolumeConfig {
231+ Type : "npipe" ,
232+ Target : "/target" ,
233+ Volume : & composetypes.ServiceVolumeVolume {
234+ NoCopy : true ,
235+ },
236+ }
237+ _ , err := convertVolumeToMount (config , volumes {}, namespace )
238+ assert .Error (t , err , "invalid npipe source, source cannot be empty" )
239+ }
240+
241+ func TestHandleNpipeToMountConflictingOptionsTmpfsInNpipe (t * testing.T ) {
242+ namespace := NewNamespace ("foo" )
243+
244+ config := composetypes.ServiceVolumeConfig {
245+ Type : "npipe" ,
246+ Source : "/foo" ,
247+ Target : "/target" ,
248+ Tmpfs : & composetypes.ServiceVolumeTmpfs {
249+ Size : 1000 ,
250+ },
251+ }
252+ _ , err := convertVolumeToMount (config , volumes {}, namespace )
253+ assert .Error (t , err , "tmpfs options are incompatible with type npipe" )
254+ }
255+
256+ func TestHandleNpipeToMountConflictingOptionsVolumeInNpipe (t * testing.T ) {
257+ namespace := NewNamespace ("foo" )
258+
259+ config := composetypes.ServiceVolumeConfig {
260+ Type : "npipe" ,
261+ Source : "/foo" ,
262+ Target : "/target" ,
263+ Volume : & composetypes.ServiceVolumeVolume {
264+ NoCopy : true ,
265+ },
266+ }
267+ _ , err := convertVolumeToMount (config , volumes {}, namespace )
268+ assert .Error (t , err , "volume options are incompatible with type npipe" )
269+ }
270+
135271func TestConvertVolumeToMountNamedVolume (t * testing.T ) {
136272 stackVolumes := volumes {
137273 "normal" : composetypes.VolumeConfig {
@@ -344,6 +480,27 @@ func TestConvertTmpfsToMountVolumeWithSource(t *testing.T) {
344480 assert .Error (t , err , "invalid tmpfs source, source must be empty" )
345481}
346482
483+ func TestHandleNpipeToMountBind (t * testing.T ) {
484+ namespace := NewNamespace ("foo" )
485+ expected := mount.Mount {
486+ Type : mount .TypeNamedPipe ,
487+ Source : "/bar" ,
488+ Target : "/foo" ,
489+ ReadOnly : true ,
490+ BindOptions : & mount.BindOptions {Propagation : mount .PropagationShared },
491+ }
492+ config := composetypes.ServiceVolumeConfig {
493+ Type : "npipe" ,
494+ Source : "/bar" ,
495+ Target : "/foo" ,
496+ ReadOnly : true ,
497+ Bind : & composetypes.ServiceVolumeBind {Propagation : "shared" },
498+ }
499+ mnt , err := convertVolumeToMount (config , volumes {}, namespace )
500+ assert .NilError (t , err )
501+ assert .Check (t , is .DeepEqual (expected , mnt ))
502+ }
503+
347504func TestConvertVolumeToMountAnonymousNpipe (t * testing.T ) {
348505 config := composetypes.ServiceVolumeConfig {
349506 Type : "npipe" ,
@@ -427,3 +584,98 @@ func TestConvertVolumeMountClusterGroup(t *testing.T) {
427584 assert .NilError (t , err )
428585 assert .Check (t , is .DeepEqual (expected , mnt ))
429586}
587+
588+ func TestHandleClusterToMountAnonymousCluster (t * testing.T ) {
589+ namespace := NewNamespace ("foo" )
590+
591+ config := composetypes.ServiceVolumeConfig {
592+ Type : "cluster" ,
593+ Target : "/target" ,
594+ Volume : & composetypes.ServiceVolumeVolume {
595+ NoCopy : true ,
596+ },
597+ }
598+ _ , err := convertVolumeToMount (config , volumes {}, namespace )
599+ assert .Error (t , err , "invalid cluster source, source cannot be empty" )
600+ }
601+
602+ func TestHandleClusterToMountConflictingOptionsTmpfsInCluster (t * testing.T ) {
603+ namespace := NewNamespace ("foo" )
604+
605+ config := composetypes.ServiceVolumeConfig {
606+ Type : "cluster" ,
607+ Source : "/foo" ,
608+ Target : "/target" ,
609+ Tmpfs : & composetypes.ServiceVolumeTmpfs {
610+ Size : 1000 ,
611+ },
612+ }
613+ _ , err := convertVolumeToMount (config , volumes {}, namespace )
614+ assert .Error (t , err , "tmpfs options are incompatible with type cluster" )
615+ }
616+
617+ func TestHandleClusterToMountConflictingOptionsVolumeInCluster (t * testing.T ) {
618+ namespace := NewNamespace ("foo" )
619+
620+ config := composetypes.ServiceVolumeConfig {
621+ Type : "cluster" ,
622+ Source : "/foo" ,
623+ Target : "/target" ,
624+ Volume : & composetypes.ServiceVolumeVolume {
625+ NoCopy : true ,
626+ },
627+ }
628+ _ , err := convertVolumeToMount (config , volumes {}, namespace )
629+ assert .Error (t , err , "volume options are incompatible with type cluster" )
630+ }
631+
632+ func TestHandleClusterToMountWithUndefinedVolumeConfig (t * testing.T ) {
633+ namespace := NewNamespace ("foo" )
634+
635+ config := composetypes.ServiceVolumeConfig {
636+ Type : "cluster" ,
637+ Source : "foo" ,
638+ Target : "/srv" ,
639+ }
640+
641+ _ , err := convertVolumeToMount (config , volumes {}, namespace )
642+ assert .Error (t , err , "undefined volume \" foo\" " )
643+ }
644+
645+ func TestHandleClusterToMountWithVolumeConfigName (t * testing.T ) {
646+ stackVolumes := volumes {
647+ "foo" : composetypes.VolumeConfig {
648+ Name : "bar" ,
649+ },
650+ }
651+
652+ config := composetypes.ServiceVolumeConfig {
653+ Type : "cluster" ,
654+ Source : "foo" ,
655+ Target : "/srv" ,
656+ }
657+
658+ expected := mount.Mount {
659+ Type : mount .TypeCluster ,
660+ Source : "bar" ,
661+ Target : "/srv" ,
662+ ClusterOptions : & mount.ClusterOptions {},
663+ }
664+
665+ mnt , err := convertVolumeToMount (config , stackVolumes , NewNamespace ("foo" ))
666+ assert .NilError (t , err )
667+ assert .Check (t , is .DeepEqual (expected , mnt ))
668+ }
669+
670+ func TestHandleClusterToMountBind (t * testing.T ) {
671+ namespace := NewNamespace ("foo" )
672+ config := composetypes.ServiceVolumeConfig {
673+ Type : "cluster" ,
674+ Source : "/bar" ,
675+ Target : "/foo" ,
676+ ReadOnly : true ,
677+ Bind : & composetypes.ServiceVolumeBind {Propagation : "shared" },
678+ }
679+ _ , err := convertVolumeToMount (config , volumes {}, namespace )
680+ assert .Error (t , err , "bind options are incompatible with type cluster" )
681+ }
0 commit comments