File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -564,12 +564,20 @@ const (
564564type ServiceVolumeBind struct {
565565 SELinux string `yaml:"selinux,omitempty" json:"selinux,omitempty"`
566566 Propagation string `yaml:"propagation,omitempty" json:"propagation,omitempty"`
567- CreateHostPath bool `yaml:"create_host_path,omitempty" json:"create_host_path,omitempty"`
567+ CreateHostPath OptOut `yaml:"create_host_path,omitempty" json:"create_host_path,omitempty"`
568568 Recursive string `yaml:"recursive,omitempty" json:"recursive,omitempty"`
569569
570570 Extensions Extensions `yaml:"#extensions,inline,omitempty" json:"-"`
571571}
572572
573+ // OptOut is a boolean which default value is 'true'
574+ type OptOut bool
575+
576+ func (o OptOut ) IsZero () bool {
577+ // Attribute can be omitted if value is true
578+ return bool (o )
579+ }
580+
573581// SELinux represents the SELinux re-labeling options.
574582const (
575583 // SELinuxShared option indicates that the bind mount content is shared among multiple containers
Original file line number Diff line number Diff line change @@ -380,3 +380,37 @@ func TestMappingValues(t *testing.T) {
380380 })
381381 assert .DeepEqual (t , mapping .Values (), values )
382382}
383+
384+ func TestMarhsall (t * testing.T ) {
385+ p := Project {
386+ Services : Services {
387+ "test" : ServiceConfig {
388+ Volumes : []ServiceVolumeConfig {
389+ {
390+ Type : "bind" ,
391+ Bind : & ServiceVolumeBind {
392+ CreateHostPath : true , // default
393+ },
394+ },
395+ {
396+ Type : "bind" ,
397+ Bind : & ServiceVolumeBind {
398+ CreateHostPath : false ,
399+ },
400+ },
401+ },
402+ },
403+ },
404+ }
405+ marshalYAML , err := p .MarshalYAML ()
406+ assert .NilError (t , err )
407+ assert .Equal (t , string (marshalYAML ), `services:
408+ test:
409+ volumes:
410+ - type: bind
411+ bind: {}
412+ - type: bind
413+ bind:
414+ create_host_path: false
415+ ` )
416+ }
You can’t perform that action at this time.
0 commit comments