Allow Windows Docker containers to map volumes (#13584)
* fix regex for windows path * Fix escaping * move validate function out and create test
This commit is contained in:
parent
0e0c61bbd8
commit
994284f535
|
@ -187,14 +187,7 @@ func resourceDockerContainer() *schema.Resource {
|
|||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
ValidateFunc: func(v interface{}, k string) (ws []string, es []error) {
|
||||
value := v.(string)
|
||||
if !regexp.MustCompile(`^/`).MatchString(value) {
|
||||
es = append(es, fmt.Errorf(
|
||||
"%q must be an absolute path", k))
|
||||
}
|
||||
return
|
||||
},
|
||||
ValidateFunc: validateDockerContainerPath,
|
||||
},
|
||||
|
||||
"volume_name": &schema.Schema{
|
||||
|
@ -515,3 +508,13 @@ func resourceDockerUploadHash(v interface{}) int {
|
|||
|
||||
return hashcode.String(buf.String())
|
||||
}
|
||||
|
||||
func validateDockerContainerPath(v interface{}, k string) (ws []string, errors []error) {
|
||||
|
||||
value := v.(string)
|
||||
if !regexp.MustCompile(`^[a-zA-Z]:\\|^/`).MatchString(value) {
|
||||
errors = append(errors, fmt.Errorf("%q must be an absolute path", k))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -27,6 +27,29 @@ func TestAccDockerContainer_basic(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccDockerContainerPath_validation(t *testing.T) {
|
||||
cases := []struct {
|
||||
Value string
|
||||
ErrCount int
|
||||
}{
|
||||
{Value: "/var/log", ErrCount: 0},
|
||||
{Value: "/tmp", ErrCount: 0},
|
||||
{Value: "C:\\Windows\\System32", ErrCount: 0},
|
||||
{Value: "C:\\Program Files\\MSBuild", ErrCount: 0},
|
||||
{Value: "test", ErrCount: 1},
|
||||
{Value: "C:Test", ErrCount: 1},
|
||||
{Value: "", ErrCount: 1},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
_, errors := validateDockerContainerPath(tc.Value, "docker_container")
|
||||
|
||||
if len(errors) != tc.ErrCount {
|
||||
t.Fatalf("Expected the Docker Container Path to trigger a validation error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccDockerContainer_volume(t *testing.T) {
|
||||
var c dc.Container
|
||||
|
||||
|
|
Loading…
Reference in New Issue