Allow underscore in database_name [redshift] (#10019)
* allow underscore in database_name [redshift] Fixes #10009 * Added Test Cases To Validate Redshift DBName * Remove Old Test Cases Regarding Redshift DBName Validation * Added More Test Cases For Redshift DBName
This commit is contained in:
parent
ed3877d672
commit
e1919edbb3
|
@ -844,9 +844,13 @@ func validateRedshiftClusterIdentifier(v interface{}, k string) (ws []string, er
|
|||
|
||||
func validateRedshiftClusterDbName(v interface{}, k string) (ws []string, errors []error) {
|
||||
value := v.(string)
|
||||
if !regexp.MustCompile(`^[0-9a-z]+$`).MatchString(value) {
|
||||
if !regexp.MustCompile(`^[0-9A-Za-z_$]+$`).MatchString(value) {
|
||||
errors = append(errors, fmt.Errorf(
|
||||
"only lowercase letters and numeric characters allowed in %q", k))
|
||||
"only alphanumeric characters, underscores, and dollar signs are allowed in %q", k))
|
||||
}
|
||||
if !regexp.MustCompile(`^[a-zA-Z_]`).MatchString(value) {
|
||||
errors = append(errors, fmt.Errorf(
|
||||
"first character of %q must be a letter or underscore", k))
|
||||
}
|
||||
if len(value) > 64 {
|
||||
errors = append(errors, fmt.Errorf(
|
||||
|
|
|
@ -13,6 +13,42 @@ import (
|
|||
"github.com/hashicorp/terraform/terraform"
|
||||
)
|
||||
|
||||
func TestValidateRedshiftClusterDbName(t *testing.T) {
|
||||
validNames := []string{
|
||||
"testdbname",
|
||||
"test_dbname",
|
||||
"testdbname123",
|
||||
"TestDBname",
|
||||
"testdbname$hashicorp",
|
||||
"_dbname",
|
||||
}
|
||||
for _, v := range validNames {
|
||||
_, errors := validateRedshiftClusterDbName(v, "name")
|
||||
if len(errors) != 0 {
|
||||
t.Fatalf("%q should be a valid Redshift DBName: %q", v, errors)
|
||||
}
|
||||
}
|
||||
|
||||
invalidNames := []string{
|
||||
"!",
|
||||
"/",
|
||||
" ",
|
||||
":",
|
||||
";",
|
||||
"test name",
|
||||
"/slash-at-the-beginning",
|
||||
"slash-at-the-end/",
|
||||
"",
|
||||
randomString(100),
|
||||
}
|
||||
for _, v := range invalidNames {
|
||||
_, errors := validateRedshiftClusterDbName(v, "name")
|
||||
if len(errors) == 0 {
|
||||
t.Fatalf("%q should be an invalid Redshift DBName", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccAWSRedshiftCluster_basic(t *testing.T) {
|
||||
var v redshift.Cluster
|
||||
|
||||
|
@ -340,42 +376,6 @@ func TestResourceAWSRedshiftClusterIdentifierValidation(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestResourceAWSRedshiftClusterDbNameValidation(t *testing.T) {
|
||||
cases := []struct {
|
||||
Value string
|
||||
ErrCount int
|
||||
}{
|
||||
{
|
||||
Value: "tEsting",
|
||||
ErrCount: 1,
|
||||
},
|
||||
{
|
||||
Value: "testing1",
|
||||
ErrCount: 0,
|
||||
},
|
||||
{
|
||||
Value: "testing-",
|
||||
ErrCount: 1,
|
||||
},
|
||||
{
|
||||
Value: "",
|
||||
ErrCount: 2,
|
||||
},
|
||||
{
|
||||
Value: randomString(65),
|
||||
ErrCount: 1,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
_, errors := validateRedshiftClusterDbName(tc.Value, "aws_redshift_cluster_database_name")
|
||||
|
||||
if len(errors) != tc.ErrCount {
|
||||
t.Fatalf("Expected the Redshift Cluster database_name to trigger a validation error")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceAWSRedshiftClusterFinalSnapshotIdentifierValidation(t *testing.T) {
|
||||
cases := []struct {
|
||||
Value string
|
||||
|
|
Loading…
Reference in New Issue