From ae43fe5f90ce3d8a8bc4defd225523fd8f9eb600 Mon Sep 17 00:00:00 2001 From: Stefan Junker Date: Fri, 3 Jun 2016 17:10:52 +0200 Subject: [PATCH] types/volume: add recursive flag This includes a unit test. --- schema/types/volume.go | 17 ++++++++++++++--- schema/types/volume_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/schema/types/volume.go b/schema/types/volume.go index c5ae5918..c2c429dc 100644 --- a/schema/types/volume.go +++ b/schema/types/volume.go @@ -40,8 +40,9 @@ type Volume struct { // currently used only by "host" // TODO(jonboulle): factor out? - Source string `json:"source,omitempty"` - ReadOnly *bool `json:"readOnly,omitempty"` + Source string `json:"source,omitempty"` + ReadOnly *bool `json:"readOnly,omitempty"` + Recursive *bool `json:"recursive,omitempty"` // currently used only by "empty" Mode *string `json:"mode,omitempty"` @@ -128,6 +129,10 @@ func (v Volume) String() string { s = append(s, ",readOnly=") s = append(s, strconv.FormatBool(*v.ReadOnly)) } + if v.Recursive != nil { + s = append(s, ",recursive=") + s = append(s, strconv.FormatBool(*v.Recursive)) + } switch v.Kind { case "empty": if *v.Mode != emptyVolumeDefaultMode { @@ -149,7 +154,7 @@ func (v Volume) String() string { // VolumeFromString takes a command line volume parameter and returns a volume // // Example volume parameters: -// database,kind=host,source=/tmp,readOnly=true +// database,kind=host,source=/tmp,readOnly=true,recursive=true func VolumeFromString(vp string) (*Volume, error) { var vol Volume @@ -186,6 +191,12 @@ func VolumeFromString(vp string) (*Volume, error) { return nil, err } vol.ReadOnly = &ro + case "recursive": + rec, err := strconv.ParseBool(val[0]) + if err != nil { + return nil, err + } + vol.Recursive = &rec case "mode": vol.Mode = &val[0] case "uid": diff --git a/schema/types/volume_test.go b/schema/types/volume_test.go index 71596871..e566157a 100644 --- a/schema/types/volume_test.go +++ b/schema/types/volume_test.go @@ -127,6 +127,32 @@ func TestVolumeToFromString(t *testing.T) { GID: ip(1000), }, }, + { + "foobar,kind=host,source=/tmp,recursive=false", + Volume{ + Name: "foobar", + Kind: "host", + Source: "/tmp", + ReadOnly: nil, + Mode: nil, + UID: nil, + GID: nil, + Recursive: bp(false), + }, + }, + { + "foobar,kind=host,source=/tmp,recursive=true", + Volume{ + Name: "foobar", + Kind: "host", + Source: "/tmp", + ReadOnly: nil, + Mode: nil, + UID: nil, + GID: nil, + Recursive: bp(true), + }, + }, } for i, tt := range tests { v, err := VolumeFromString(tt.s) @@ -153,6 +179,7 @@ func TestVolumeFromStringBad(t *testing.T) { "foobar,kind=host,mode=0755", "foobar,kind=host,mode=0600,readOnly=true,gid=0", "foobar,kind=empty,source=/tmp", + "foobar,kind=host,source=/tmp,recursive=MAYBE", } for i, in := range tests { l, err := VolumeFromString(in)