@@ -217,3 +217,86 @@ func TestMountOptSetTmpfsError(t *testing.T) {
217217 assert .ErrorContains (t , m .Set ("type=tmpfs,target=/foo,tmpfs-mode=foo" ), "invalid value for tmpfs-mode" )
218218 assert .ErrorContains (t , m .Set ("type=tmpfs" ), "target is required" )
219219}
220+
221+ func TestMountOptSetBindNonRecursive (t * testing.T ) {
222+ var mount MountOpt
223+ assert .NilError (t , mount .Set ("type=bind,source=/foo,target=/bar,bind-nonrecursive" ))
224+ assert .Check (t , is .DeepEqual ([]mounttypes.Mount {
225+ {
226+ Type : mounttypes .TypeBind ,
227+ Source : "/foo" ,
228+ Target : "/bar" ,
229+ BindOptions : & mounttypes.BindOptions {
230+ NonRecursive : true ,
231+ },
232+ },
233+ }, mount .Value ()))
234+ }
235+
236+ func TestMountOptSetBindRecursive (t * testing.T ) {
237+ t .Run ("enabled" , func (t * testing.T ) {
238+ var mount MountOpt
239+ assert .NilError (t , mount .Set ("type=bind,source=/foo,target=/bar,bind-recursive=enabled" ))
240+ assert .Check (t , is .DeepEqual ([]mounttypes.Mount {
241+ {
242+ Type : mounttypes .TypeBind ,
243+ Source : "/foo" ,
244+ Target : "/bar" ,
245+ },
246+ }, mount .Value ()))
247+ })
248+
249+ t .Run ("disabled" , func (t * testing.T ) {
250+ var mount MountOpt
251+ assert .NilError (t , mount .Set ("type=bind,source=/foo,target=/bar,bind-recursive=disabled" ))
252+ assert .Check (t , is .DeepEqual ([]mounttypes.Mount {
253+ {
254+ Type : mounttypes .TypeBind ,
255+ Source : "/foo" ,
256+ Target : "/bar" ,
257+ BindOptions : & mounttypes.BindOptions {
258+ NonRecursive : true ,
259+ },
260+ },
261+ }, mount .Value ()))
262+ })
263+
264+ t .Run ("writable" , func (t * testing.T ) {
265+ var mount MountOpt
266+ assert .Error (t , mount .Set ("type=bind,source=/foo,target=/bar,bind-recursive=writable" ),
267+ "option 'bind-recursive=writable' requires 'readonly' to be specified in conjunction" )
268+ assert .NilError (t , mount .Set ("type=bind,source=/foo,target=/bar,bind-recursive=writable,readonly" ))
269+ assert .Check (t , is .DeepEqual ([]mounttypes.Mount {
270+ {
271+ Type : mounttypes .TypeBind ,
272+ Source : "/foo" ,
273+ Target : "/bar" ,
274+ ReadOnly : true ,
275+ BindOptions : & mounttypes.BindOptions {
276+ ReadOnlyNonRecursive : true ,
277+ },
278+ },
279+ }, mount .Value ()))
280+ })
281+
282+ t .Run ("readonly" , func (t * testing.T ) {
283+ var mount MountOpt
284+ assert .Error (t , mount .Set ("type=bind,source=/foo,target=/bar,bind-recursive=readonly" ),
285+ "option 'bind-recursive=readonly' requires 'readonly' to be specified in conjunction" )
286+ assert .Error (t , mount .Set ("type=bind,source=/foo,target=/bar,bind-recursive=readonly,readonly" ),
287+ "option 'bind-recursive=readonly' requires 'bind-propagation=rprivate' to be specified in conjunction" )
288+ assert .NilError (t , mount .Set ("type=bind,source=/foo,target=/bar,bind-recursive=readonly,readonly,bind-propagation=rprivate" ))
289+ assert .Check (t , is .DeepEqual ([]mounttypes.Mount {
290+ {
291+ Type : mounttypes .TypeBind ,
292+ Source : "/foo" ,
293+ Target : "/bar" ,
294+ ReadOnly : true ,
295+ BindOptions : & mounttypes.BindOptions {
296+ ReadOnlyForceRecursive : true ,
297+ Propagation : mounttypes .PropagationRPrivate ,
298+ },
299+ },
300+ }, mount .Value ()))
301+ })
302+ }
0 commit comments