-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove acr validator from scopemaps (#11784)
Remove incorrect validator from scopemaps, as mentioned in #11783
- Loading branch information
Showing
3 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
azurerm/internal/services/containers/validate/container_registry_scope_map_name.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package validate | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
func ContainerRegistryScopeMapName(v interface{}, k string) (warnings []string, errors []error) { | ||
value := v.(string) | ||
if !regexp.MustCompile(`^[a-zA-Z0-9\-]+$`).MatchString(value) { | ||
errors = append(errors, fmt.Errorf( | ||
"alpha numeric characters and hyphens only are allowed in %q: %q", k, value)) | ||
} | ||
|
||
if 5 > len(value) { | ||
errors = append(errors, fmt.Errorf("%q cannot be less than 5 characters: %q", k, value)) | ||
} | ||
|
||
if len(value) >= 50 { | ||
errors = append(errors, fmt.Errorf("%q cannot be longer than 50 characters: %q %d", k, value, len(value))) | ||
} | ||
|
||
return warnings, errors | ||
} |
68 changes: 68 additions & 0 deletions
68
azurerm/internal/services/containers/validate/container_registry_scope_map_name_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package validate_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/containers/validate" | ||
) | ||
|
||
func TestContainerRegistryScopeMapName(t *testing.T) { | ||
cases := []struct { | ||
Value string | ||
ErrCount int | ||
}{ | ||
{ | ||
Value: "four", | ||
ErrCount: 1, | ||
}, | ||
{ | ||
Value: "5five", | ||
ErrCount: 0, | ||
}, | ||
{ | ||
Value: "five-123", | ||
ErrCount: 0, | ||
}, | ||
{ | ||
Value: "hello-world", | ||
ErrCount: 0, | ||
}, | ||
{ | ||
Value: "hello_world", | ||
ErrCount: 1, | ||
}, | ||
{ | ||
Value: "helloWorld", | ||
ErrCount: 0, | ||
}, | ||
{ | ||
Value: "helloworld12", | ||
ErrCount: 0, | ||
}, | ||
{ | ||
Value: "hello@world", | ||
ErrCount: 1, | ||
}, | ||
|
||
{ | ||
Value: "qfvbdsbvipqdbwsbddbdcwqffewsqwcdw21ddwqwd3324120", | ||
ErrCount: 0, | ||
}, | ||
{ | ||
Value: "qfvbdsbvipqdbwsbddbdcwqffewsqwcdw21ddwqwd33241202", | ||
ErrCount: 0, | ||
}, | ||
{ | ||
Value: "qfvbdsbvipqdbwsbddbdcwqfjjfewsqwcdw21ddwqwd3324120fadfadf", | ||
ErrCount: 1, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
_, errors := validate.ContainerRegistryScopeMapName(tc.Value, "azurerm_container_registry_scope_map") | ||
|
||
if len(errors) != tc.ErrCount { | ||
t.Fatalf("Expected the Azure RM Container Registry Token Name to trigger a validation error: %v", errors) | ||
} | ||
} | ||
} |