Skip to content

Commit 3f56ba9

Browse files
authored
Merge pull request #95 from storey247/ds/adls2mountvalidation
Standardised the validate logic found azure mounts
2 parents 34e68d5 + 5177ee4 commit 3f56ba9

File tree

5 files changed

+35
-16
lines changed

5 files changed

+35
-16
lines changed

databricks/mounts.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,12 @@ func ProcessAzureWasbAbfssUris(uri string) (string, string, string, error) {
435435
}
436436
return containerName, storageAccount, directory, nil
437437
}
438+
439+
// ValidateMountDirectory is a ValidateFunc that ensures the mount directory starts with a '/'
440+
func ValidateMountDirectory(val interface{}, key string) (warns []string, errs []error) {
441+
v := val.(string)
442+
if v != "" && !strings.HasPrefix(v, "/") {
443+
return nil, []error{fmt.Errorf("%s must start with /, got: %s", key, v)}
444+
}
445+
return nil, nil
446+
}

databricks/mounts_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package databricks
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestValidateMountDirectory(t *testing.T) {
10+
testCases := []struct {
11+
directory string
12+
errorCount int
13+
}{
14+
{"", 0},
15+
{"/directory", 0},
16+
{"directory", 1},
17+
}
18+
for _, tc := range testCases {
19+
_, errs := ValidateMountDirectory(tc.directory, "key")
20+
21+
assert.Lenf(t, errs, tc.errorCount, "directory '%s' does not generate the expected error count", tc.directory)
22+
}
23+
}

databricks/resource_databricks_azure_adls_gen1_mount.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,7 @@ func resourceAzureAdlsGen1Mount() *schema.Resource {
4040
Computed: true,
4141
//Default: "/",
4242
ForceNew: true,
43-
ValidateFunc: func(val interface{}, key string) (warns []string, errors []error) {
44-
directory := val.(string)
45-
if strings.HasPrefix(directory, "/") {
46-
return
47-
}
48-
errors = append(errors, fmt.Errorf("%s must start with /, got: %s", key, val))
49-
return
50-
},
43+
ValidateFunc: ValidateMountDirectory,
5144
},
5245
"mount_name": {
5346
Type: schema.TypeString,

databricks/resource_databricks_azure_adls_gen2_mount.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func resourceAzureAdlsGen2Mount() *schema.Resource {
3636
Optional: true,
3737
Computed: true,
3838
ForceNew: true,
39+
ValidateFunc: ValidateMountDirectory,
3940
},
4041
"mount_name": {
4142
Type: schema.TypeString,

databricks/resource_databricks_azure_blob_mount.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,7 @@ func resourceAzureBlobMount() *schema.Resource {
3838
Computed: true,
3939
//Default: "/",
4040
ForceNew: true,
41-
ValidateFunc: func(val interface{}, key string) (warns []string, errors []error) {
42-
directory := val.(string)
43-
if strings.HasPrefix(directory, "/") {
44-
return
45-
}
46-
errors = append(errors, fmt.Errorf("%s must start with /, got: %s", key, val))
47-
return
48-
},
41+
ValidateFunc: ValidateMountDirectory,
4942
},
5043
"mount_name": {
5144
Type: schema.TypeString,

0 commit comments

Comments
 (0)