Refactoring the multiple tests into a simple test case with multiple inputs as per feedback

This commit is contained in:
stack72 2015-10-08 12:15:59 +01:00
parent 97188d6583
commit bd78dfd885
1 changed files with 35 additions and 50 deletions

View File

@ -108,57 +108,42 @@ func TestAccAWSDBParameterGroupOnly(t *testing.T) {
}) })
} }
func TestResourceAWSDBParameterGroupName_uppercaseCharacter(t *testing.T) { func TestResourceAWSDBParameterGroupName_validation(t *testing.T) {
var dbParamGroupName = "tEsting123" cases := []struct {
_, errors := validateDbParamGroupName(dbParamGroupName, "aws_db_parameter_group_name") Value string
ErrCount int
if len(errors) != 1 { }{
t.Fatalf("Expected the DB Parameter Group Name to trigger a validation error") {
Value: "tEsting123",
ErrCount: 1,
},
{
Value: "testing123!",
ErrCount: 1,
},
{
Value: "1testing123",
ErrCount: 1,
},
{
Value: "testing--123",
ErrCount: 1,
},
{
Value: "testing123-",
ErrCount: 1,
},
{
Value: randomString(256),
ErrCount: 1,
},
} }
}
func TestResourceAWSDBParameterGroupName_specialCharacters(t *testing.T) { for _, tc := range cases {
var dbParamGroupName = "testing123!" _, errors := validateDbParamGroupName(tc.Value, "aws_db_parameter_group_name")
_, errors := validateDbParamGroupName(dbParamGroupName, "SampleKey") if len(errors) != tc.ErrCount {
t.Fatalf("Expected the DB Parameter Group Name to trigger a validation error")
if len(errors) != 1 { }
t.Fatalf("Expected the DB Parameter Group Name to trigger a validation error")
}
}
func TestResourceAWSDBParameterGroupName_firstCharacterNumber(t *testing.T) {
var dbParamGroupName = "1testing123"
_, errors := validateDbParamGroupName(dbParamGroupName, "SampleKey")
if len(errors) != 1 {
t.Fatalf("Expected the DB Parameter Group Name to trigger a validation error")
}
}
func TestResourceAWSDBParameterGroupName_doubleHyphen(t *testing.T) {
var dbParamGroupName = "testing--123"
_, errors := validateDbParamGroupName(dbParamGroupName, "SampleKey")
if len(errors) != 1 {
t.Fatalf("Expected the DB Parameter Group Name to trigger a validation error")
}
}
func TestResourceAWSDBParameterGroupName_trailingHyphen(t *testing.T) {
var dbParamGroupName = "testing123-"
_, errors := validateDbParamGroupName(dbParamGroupName, "SampleKey")
if len(errors) != 1 {
t.Fatalf("Expected the DB Parameter Group Name to trigger a validation error")
}
}
func TestResourceAWSDBParameterGroupName_tooManyCharacters(t *testing.T) {
dbParamGroupName := RandomString(256)
_, errors := validateDbParamGroupName(dbParamGroupName, "SampleKey")
if len(errors) != 1 {
t.Fatalf("Expected the DB Parameter Group Name to trigger a validation error")
} }
} }
@ -249,7 +234,7 @@ func testAccCheckAWSDBParameterGroupExists(n string, v *rds.DBParameterGroup) re
} }
} }
func RandomString(strlen int) string { func randomString(strlen int) string {
rand.Seed(time.Now().UTC().UnixNano()) rand.Seed(time.Now().UTC().UnixNano())
const chars = "abcdefghijklmnopqrstuvwxyz0123456789" const chars = "abcdefghijklmnopqrstuvwxyz0123456789"
result := make([]byte, strlen) result := make([]byte, strlen)