Adding a RandomString generator to test for db_param_group_name being too long

This commit is contained in:
stack72 2015-10-08 10:05:50 +01:00
parent cc56431b97
commit 97188d6583
1 changed files with 21 additions and 0 deletions

View File

@ -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"