update read replica acceptance test

This commit is contained in:
Clint Shryock 2015-05-20 09:28:33 -05:00
parent dc164c454e
commit 6b6aa867c0
2 changed files with 45 additions and 42 deletions

View File

@ -670,6 +670,10 @@ func resourceAwsDbInstanceStateRefreshFunc(
return nil, "", nil
}
if v.DBInstanceStatus != nil {
log.Printf("[DEBUG] DB Instance status for instance %s: %s", d.Id(), *v.DBInstanceStatus)
}
return v, *v.DBInstanceStatus, nil
}
}

View File

@ -50,28 +50,19 @@ func TestAccAWSDBInstance(t *testing.T) {
}
func TestAccAWSDBInstanceReplica(t *testing.T) {
// var v rds.DBInstance
var r rds.DBInstance
var s, r rds.DBInstance
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSDBInstanceDestroy,
Steps: []resource.TestStep{
// resource.TestStep{
// Config: testAccAWSDBInstanceConfig,
// Check: resource.ComposeTestCheckFunc(
// testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &v),
// ),
// },
resource.TestStep{
Config: testAccAWSDBInstanceReplicaConfig,
Config: testAccReplicaInstanceConfig(rand.New(rand.NewSource(time.Now().UnixNano())).Int()),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSDBInstanceExists("aws_db_instance.bar", &s),
testAccCheckAWSDBInstanceExists("aws_db_instance.replica", &r),
resource.TestCheckResourceAttr(
"aws_db_instance.replica", "replicate_source_db", "tf-update-more"),
testAccCheckAWSDBInstanceReplicaAttributes(&r),
testAccCheckAWSDBInstanceReplicaAttributes(&s, &r),
),
},
},
@ -132,23 +123,11 @@ func testAccCheckAWSDBInstanceAttributes(v *rds.DBInstance) resource.TestCheckFu
}
}
func testAccCheckAWSDBInstanceReplicaAttributes(r *rds.DBInstance) resource.TestCheckFunc {
func testAccCheckAWSDBInstanceReplicaAttributes(source, replica *rds.DBInstance) resource.TestCheckFunc {
return func(s *terraform.State) error {
// if *v.Engine != "mysql" {
// return fmt.Errorf("bad engine: %#v", *v.Engine)
// }
// if *v.EngineVersion != "5.6.21" {
// return fmt.Errorf("bad engine_version: %#v", *v.EngineVersion)
// }
// if *v.BackupRetentionPeriod != 0 {
// return fmt.Errorf("bad backup_retention_period: %#v", *v.BackupRetentionPeriod)
// }
if r.ReadReplicaSourceDBInstanceIdentifier != nil && *r.ReadReplicaSourceDBInstanceIdentifier != "tf-update-more" {
return fmt.Errorf("bad source identifier for replica, got: %#v, expected: 'tf-update-more'", *r.ReadReplicaSourceDBInstanceIdentifier)
if replica.ReadReplicaSourceDBInstanceIdentifier != nil && *replica.ReadReplicaSourceDBInstanceIdentifier != *source.DBInstanceIdentifier {
return fmt.Errorf("bad source identifier for replica, expected: '%s', got: '%s'", *source.DBInstanceIdentifier, *replica.ReadReplicaSourceDBInstanceIdentifier)
}
return nil
@ -209,17 +188,37 @@ resource "aws_db_instance" "bar" {
parameter_group_name = "default.mysql5.6"
}`, rand.New(rand.NewSource(time.Now().UnixNano())).Int())
var testAccAWSDBInstanceReplicaConfig = fmt.Sprintf(`
resource "aws_db_instance" "replica" {
identifier = "tf-replica-db-%d"
replicate_source_db = "tf-update-more"
allocated_storage = 5
engine = "mysql"
engine_version = "5.6.19b"
instance_class = "db.t1.micro"
password = "fofofofxx"
username = "foo"
tags {
Name = "tf-replica-db"
}
}`, rand.New(rand.NewSource(time.Now().UnixNano())).Int())
func testAccReplicaInstanceConfig(val int) string {
return fmt.Sprintf(`
resource "aws_db_instance" "bar" {
identifier = "foobarbaz-test-terraform-%d"
allocated_storage = 5
engine = "mysql"
engine_version = "5.6.21"
instance_class = "db.t1.micro"
name = "baz"
password = "barbarbarbar"
username = "foo"
backup_retention_period = 1
parameter_group_name = "default.mysql5.6"
}
resource "aws_db_instance" "replica" {
identifier = "tf-replica-db-%d"
backup_retention_period = 0
replicate_source_db = "${aws_db_instance.bar.identifier}"
allocated_storage = "${aws_db_instance.bar.allocated_storage}"
engine = "${aws_db_instance.bar.engine}"
engine_version = "${aws_db_instance.bar.engine_version}"
instance_class = "${aws_db_instance.bar.instance_class}"
password = "${aws_db_instance.bar.password}"
username = "${aws_db_instance.bar.username}"
tags {
Name = "tf-replica-db"
}
}
`, val, val)
}