Skip to content

Commit

Permalink
Merge pull request #95 from storey247/ds/adls2mountvalidation
Browse files Browse the repository at this point in the history
Standardised the validate logic found azure mounts
  • Loading branch information
stikkireddy committed Jun 12, 2020
2 parents 34e68d5 + 5177ee4 commit 3f56ba9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
9 changes: 9 additions & 0 deletions databricks/mounts.go
Expand Up @@ -435,3 +435,12 @@ func ProcessAzureWasbAbfssUris(uri string) (string, string, string, error) {
}
return containerName, storageAccount, directory, nil
}

// ValidateMountDirectory is a ValidateFunc that ensures the mount directory starts with a '/'
func ValidateMountDirectory(val interface{}, key string) (warns []string, errs []error) {
v := val.(string)
if v != "" && !strings.HasPrefix(v, "/") {
return nil, []error{fmt.Errorf("%s must start with /, got: %s", key, v)}
}
return nil, nil
}
23 changes: 23 additions & 0 deletions databricks/mounts_test.go
@@ -0,0 +1,23 @@
package databricks

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestValidateMountDirectory(t *testing.T) {
testCases := []struct {
directory string
errorCount int
}{
{"", 0},
{"/directory", 0},
{"directory", 1},
}
for _, tc := range testCases {
_, errs := ValidateMountDirectory(tc.directory, "key")

assert.Lenf(t, errs, tc.errorCount, "directory '%s' does not generate the expected error count", tc.directory)
}
}
9 changes: 1 addition & 8 deletions databricks/resource_databricks_azure_adls_gen1_mount.go
Expand Up @@ -40,14 +40,7 @@ func resourceAzureAdlsGen1Mount() *schema.Resource {
Computed: true,
//Default: "/",
ForceNew: true,
ValidateFunc: func(val interface{}, key string) (warns []string, errors []error) {
directory := val.(string)
if strings.HasPrefix(directory, "/") {
return
}
errors = append(errors, fmt.Errorf("%s must start with /, got: %s", key, val))
return
},
ValidateFunc: ValidateMountDirectory,
},
"mount_name": {
Type: schema.TypeString,
Expand Down
1 change: 1 addition & 0 deletions databricks/resource_databricks_azure_adls_gen2_mount.go
Expand Up @@ -36,6 +36,7 @@ func resourceAzureAdlsGen2Mount() *schema.Resource {
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: ValidateMountDirectory,
},
"mount_name": {
Type: schema.TypeString,
Expand Down
9 changes: 1 addition & 8 deletions databricks/resource_databricks_azure_blob_mount.go
Expand Up @@ -38,14 +38,7 @@ func resourceAzureBlobMount() *schema.Resource {
Computed: true,
//Default: "/",
ForceNew: true,
ValidateFunc: func(val interface{}, key string) (warns []string, errors []error) {
directory := val.(string)
if strings.HasPrefix(directory, "/") {
return
}
errors = append(errors, fmt.Errorf("%s must start with /, got: %s", key, val))
return
},
ValidateFunc: ValidateMountDirectory,
},
"mount_name": {
Type: schema.TypeString,
Expand Down

0 comments on commit 3f56ba9

Please sign in to comment.