From 97188d65834ab38a7b8d63daa05bbff33a8de453 Mon Sep 17 00:00:00 2001 From: stack72 Date: Thu, 8 Oct 2015 10:05:50 +0100 Subject: [PATCH] Adding a RandomString generator to test for db_param_group_name being too long --- .../resource_aws_db_parameter_group_test.go | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/builtin/providers/aws/resource_aws_db_parameter_group_test.go b/builtin/providers/aws/resource_aws_db_parameter_group_test.go index 354c16db9..2df4ce3c4 100644 --- a/builtin/providers/aws/resource_aws_db_parameter_group_test.go +++ b/builtin/providers/aws/resource_aws_db_parameter_group_test.go @@ -2,7 +2,9 @@ package aws import ( "fmt" + "math/rand" "testing" + "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" @@ -151,6 +153,15 @@ func TestResourceAWSDBParameterGroupName_trailingHyphen(t *testing.T) { } } +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") + } +} + func testAccCheckAWSDBParameterGroupDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).rdsconn @@ -238,6 +249,16 @@ func testAccCheckAWSDBParameterGroupExists(n string, v *rds.DBParameterGroup) re } } +func RandomString(strlen int) string { + rand.Seed(time.Now().UTC().UnixNano()) + const chars = "abcdefghijklmnopqrstuvwxyz0123456789" + result := make([]byte, strlen) + for i := 0; i < strlen; i++ { + result[i] = chars[rand.Intn(len(chars))] + } + return string(result) +} + const testAccAWSDBParameterGroupConfig = ` resource "aws_db_parameter_group" "bar" { name = "parameter-group-test-terraform"