Skip to content

Commit

Permalink
validation: allowing for nested directories
Browse files Browse the repository at this point in the history
```
=== RUN   TestValidateStorageShareDirectoryName
--- PASS: TestValidateStorageShareDirectoryName (0.00s)
    storage_test.go:49: [DEBUG] Test Input ""
    storage_test.go:49: [DEBUG] Test Input "abc123"
    storage_test.go:49: [DEBUG] Test Input "123abc"
    storage_test.go:49: [DEBUG] Test Input "123-abc"
    storage_test.go:49: [DEBUG] Test Input "-123-abc"
    storage_test.go:49: [DEBUG] Test Input "123-abc-"
    storage_test.go:49: [DEBUG] Test Input "123--abc"
    storage_test.go:49: [DEBUG] Test Input "hello/world"
    storage_test.go:49: [DEBUG] Test Input "hello/"
PASS
```
  • Loading branch information
tombuildsstuff committed Aug 22, 2019
1 parent 7bbe611 commit 30e0f9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion azurerm/helpers/validate/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ func StorageShareDirectoryName(v interface{}, k string) (warnings []string, erro

// File share names can contain only lowercase letters, numbers, and hyphens,
// and must begin and end with a letter or a number.
if !regexp.MustCompile(`^[a-z0-9][a-z0-9-]+[a-z0-9]$`).MatchString(value) {
// however they can be nested (e.g. foo/bar)
if !regexp.MustCompile(`^[a-z0-9][a-z0-9-]+[a-z0-9]$`).MatchString(value) && !regexp.MustCompile(`^[a-z0-9]{1,}/[a-z0-9]{1,}$`).MatchString(value) {
errors = append(errors, fmt.Errorf("%s must contain only lowercase alphanumeric characters, numbers and hyphens. It must start and end with a letter and end only with a number or letter", k))
}

Expand Down
8 changes: 8 additions & 0 deletions azurerm/helpers/validate/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ func TestValidateStorageShareDirectoryName(t *testing.T) {
Input: "123--abc",
Expected: false,
},
{
Input: "hello/world",
Expected: true,
},
{
Input: "hello/",
Expected: false,
},
}

for _, v := range testCases {
Expand Down

0 comments on commit 30e0f9b

Please sign in to comment.