volume/mounts: add constructors for each parser
This adds constructors for the Linux, Windows, and LCOW, to allow using these parsers externally. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
df179a1d6a
commit
28b0f47599
|
@ -7,6 +7,11 @@ import (
|
||||||
"github.com/docker/docker/api/types/mount"
|
"github.com/docker/docker/api/types/mount"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewLCOWParser creates a parser with Linux Containers on Windows semantics.
|
||||||
|
func NewLCOWParser() Parser {
|
||||||
|
return &lcowParser{}
|
||||||
|
}
|
||||||
|
|
||||||
// rxLCOWDestination is the regex expression for the mount destination for LCOW
|
// rxLCOWDestination is the regex expression for the mount destination for LCOW
|
||||||
//
|
//
|
||||||
// Destination (aka container path):
|
// Destination (aka container path):
|
||||||
|
|
|
@ -80,7 +80,7 @@ func TestLCOWParseMountRaw(t *testing.T) {
|
||||||
`\\.\pipe\foo:/foo`: `Linux containers on Windows do not support named pipe mounts`,
|
`\\.\pipe\foo:/foo`: `Linux containers on Windows do not support named pipe mounts`,
|
||||||
}
|
}
|
||||||
|
|
||||||
parser := &lcowParser{}
|
parser := NewLCOWParser()
|
||||||
|
|
||||||
for _, path := range valid {
|
for _, path := range valid {
|
||||||
if _, err := parser.ParseMountRaw(path, "local"); err != nil {
|
if _, err := parser.ParseMountRaw(path, "local"); err != nil {
|
||||||
|
@ -129,7 +129,7 @@ func TestLCOWParseMountRawSplit(t *testing.T) {
|
||||||
{`c:\foo\bar:\\.\pipe\foo`, "local", mount.TypeNamedPipe, ``, ``, "", "", true, true},
|
{`c:\foo\bar:\\.\pipe\foo`, "local", mount.TypeNamedPipe, ``, ``, "", "", true, true},
|
||||||
}
|
}
|
||||||
|
|
||||||
parser := &lcowParser{}
|
parser := NewLCOWParser()
|
||||||
for i, c := range cases {
|
for i, c := range cases {
|
||||||
t.Logf("case %d", i)
|
t.Logf("case %d", i)
|
||||||
m, err := parser.ParseMountRaw(c.bind, c.driver)
|
m, err := parser.ParseMountRaw(c.bind, c.driver)
|
||||||
|
|
|
@ -12,6 +12,11 @@ import (
|
||||||
"github.com/docker/docker/volume"
|
"github.com/docker/docker/volume"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewLinuxParser creates a parser with Linux semantics.
|
||||||
|
func NewLinuxParser() Parser {
|
||||||
|
return &linuxParser{}
|
||||||
|
}
|
||||||
|
|
||||||
type linuxParser struct{}
|
type linuxParser struct{}
|
||||||
|
|
||||||
func linuxSplitRawSpec(raw string) ([]string, error) {
|
func linuxSplitRawSpec(raw string) ([]string, error) {
|
||||||
|
|
|
@ -79,7 +79,7 @@ func TestLinuxParseMountRaw(t *testing.T) {
|
||||||
"name:/absolute-path:rprivate": "invalid volume specification",
|
"name:/absolute-path:rprivate": "invalid volume specification",
|
||||||
}
|
}
|
||||||
|
|
||||||
parser := &linuxParser{}
|
parser := NewLinuxParser()
|
||||||
|
|
||||||
for _, path := range valid {
|
for _, path := range valid {
|
||||||
if _, err := parser.ParseMountRaw(path, "local"); err != nil {
|
if _, err := parser.ParseMountRaw(path, "local"); err != nil {
|
||||||
|
@ -125,7 +125,7 @@ func TestLinuxParseMountRawSplit(t *testing.T) {
|
||||||
{"/tmp:tmp", "", mount.TypeBind, "", "", "", "", true, true},
|
{"/tmp:tmp", "", mount.TypeBind, "", "", "", "", true, true},
|
||||||
}
|
}
|
||||||
|
|
||||||
parser := &linuxParser{}
|
parser := NewLinuxParser()
|
||||||
for i, c := range cases {
|
for i, c := range cases {
|
||||||
t.Logf("case %d", i)
|
t.Logf("case %d", i)
|
||||||
m, err := parser.ParseMountRaw(c.bind, c.driver)
|
m, err := parser.ParseMountRaw(c.bind, c.driver)
|
||||||
|
@ -191,7 +191,7 @@ func TestLinuxParseMountSpecBindWithFileinfoError(t *testing.T) {
|
||||||
testErr := fmt.Errorf("some crazy error")
|
testErr := fmt.Errorf("some crazy error")
|
||||||
currentFileInfoProvider = &mockFiProviderWithError{err: testErr}
|
currentFileInfoProvider = &mockFiProviderWithError{err: testErr}
|
||||||
|
|
||||||
parser := &linuxParser{}
|
parser := NewLinuxParser()
|
||||||
|
|
||||||
_, err := parser.ParseMountSpec(mount.Mount{
|
_, err := parser.ParseMountSpec(mount.Mount{
|
||||||
Type: mount.TypeBind,
|
Type: mount.TypeBind,
|
||||||
|
@ -222,7 +222,7 @@ func TestConvertTmpfsOptions(t *testing.T) {
|
||||||
unexpectedSubstrings: []string{},
|
unexpectedSubstrings: []string{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
p := &linuxParser{}
|
p := NewLinuxParser()
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
data, err := p.ConvertTmpfsOptions(&c.opt, c.readOnly)
|
data, err := p.ConvertTmpfsOptions(&c.opt, c.readOnly)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -36,7 +36,7 @@ type Parser interface {
|
||||||
// NewParser creates a parser for the current host OS
|
// NewParser creates a parser for the current host OS
|
||||||
func NewParser() Parser {
|
func NewParser() Parser {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
return &windowsParser{}
|
return NewWindowsParser()
|
||||||
}
|
}
|
||||||
return &linuxParser{}
|
return NewLinuxParser()
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ func TestValidateMount(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
parser = &lcowParser{}
|
parser = NewLCOWParser()
|
||||||
for i, x := range lcowCases {
|
for i, x := range lcowCases {
|
||||||
err := parser.ValidateMountConfig(&x.input)
|
err := parser.ValidateMountConfig(&x.input)
|
||||||
if err == nil && x.expected == nil {
|
if err == nil && x.expected == nil {
|
||||||
|
|
|
@ -12,6 +12,11 @@ import (
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewWindowsParser creates a parser with Windows semantics.
|
||||||
|
func NewWindowsParser() Parser {
|
||||||
|
return &windowsParser{}
|
||||||
|
}
|
||||||
|
|
||||||
type windowsParser struct{}
|
type windowsParser struct{}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -87,7 +87,7 @@ func TestWindowsParseMountRaw(t *testing.T) {
|
||||||
`\\.\pipe\foo:c:\pipe`: `'c:\pipe' is not a valid pipe path`,
|
`\\.\pipe\foo:c:\pipe`: `'c:\pipe' is not a valid pipe path`,
|
||||||
}
|
}
|
||||||
|
|
||||||
parser := &windowsParser{}
|
parser := NewWindowsParser()
|
||||||
|
|
||||||
for _, path := range valid {
|
for _, path := range valid {
|
||||||
if _, err := parser.ParseMountRaw(path, "local"); err != nil {
|
if _, err := parser.ParseMountRaw(path, "local"); err != nil {
|
||||||
|
@ -137,7 +137,7 @@ func TestWindowsParseMountRawSplit(t *testing.T) {
|
||||||
{`c:\foo\bar:\\.\pipe\foo`, "local", mount.TypeNamedPipe, ``, ``, "", "", true, true},
|
{`c:\foo\bar:\\.\pipe\foo`, "local", mount.TypeNamedPipe, ``, ``, "", "", true, true},
|
||||||
}
|
}
|
||||||
|
|
||||||
parser := &windowsParser{}
|
parser := NewWindowsParser()
|
||||||
for i, c := range cases {
|
for i, c := range cases {
|
||||||
t.Logf("case %d", i)
|
t.Logf("case %d", i)
|
||||||
m, err := parser.ParseMountRaw(c.bind, c.driver)
|
m, err := parser.ParseMountRaw(c.bind, c.driver)
|
||||||
|
@ -203,7 +203,7 @@ func TestWindowsParseMountSpecBindWithFileinfoError(t *testing.T) {
|
||||||
testErr := fmt.Errorf("some crazy error")
|
testErr := fmt.Errorf("some crazy error")
|
||||||
currentFileInfoProvider = &mockFiProviderWithError{err: testErr}
|
currentFileInfoProvider = &mockFiProviderWithError{err: testErr}
|
||||||
|
|
||||||
parser := &windowsParser{}
|
parser := NewWindowsParser()
|
||||||
|
|
||||||
_, err := parser.ParseMountSpec(mount.Mount{
|
_, err := parser.ParseMountSpec(mount.Mount{
|
||||||
Type: mount.TypeBind,
|
Type: mount.TypeBind,
|
||||||
|
|
Loading…
Reference in New Issue