providers/aws: peering connection id-only test settings

This commit is contained in:
Mitchell Hashimoto 2016-04-20 12:19:21 -07:00
parent 30d501b3f0
commit ff7b58f032
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 24 additions and 5 deletions

View File

@ -147,7 +147,6 @@ func resourceAwsVPCPeeringUpdate(d *schema.ResourceData, meta interface{}) error
}
if _, ok := d.GetOk("auto_accept"); ok {
pcRaw, _, err := resourceAwsVPCPeeringConnectionStateRefreshFunc(conn, d.Id())()
if err != nil {
@ -160,7 +159,6 @@ func resourceAwsVPCPeeringUpdate(d *schema.ResourceData, meta interface{}) error
pc := pcRaw.(*ec2.VpcPeeringConnection)
if pc.Status != nil && *pc.Status.Code == "pending-acceptance" {
status, err := resourceVPCPeeringConnectionAccept(conn, d.Id())
if err != nil {
return err

View File

@ -22,6 +22,10 @@ func TestAccAWSVPCPeeringConnection_basic(t *testing.T) {
t.Fatal("AWS_ACCOUNT_ID must be set")
}
},
IDRefreshName: "aws_vpc_peering_connection.foo",
IDRefreshIgnore: []string{"auto_accept"},
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSVpcPeeringConnectionDestroy,
Steps: []resource.TestStep{
@ -59,6 +63,10 @@ func TestAccAWSVPCPeeringConnection_plan(t *testing.T) {
t.Fatal("AWS_ACCOUNT_ID must be set")
}
},
IDRefreshName: "aws_vpc_peering_connection.foo",
IDRefreshIgnore: []string{"auto_accept"},
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSVpcPeeringConnectionDestroy,
Steps: []resource.TestStep{
@ -82,7 +90,11 @@ func TestAccAWSVPCPeeringConnection_tags(t *testing.T) {
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: "aws_vpc_peering_connection.foo",
IDRefreshIgnore: []string{"auto_accept"},
Providers: testAccProviders,
CheckDestroy: testAccCheckVpcDestroy,
Steps: []resource.TestStep{

View File

@ -70,8 +70,11 @@ type TestCase struct {
//
// IDRefreshName is the name of the resource to check. This will
// default to the first non-nil primary resource in the state.
//
// IDRefreshIgnore is a list of configuration keys that will be ignored.
DisableIDRefresh bool
IDRefreshName string
IDRefreshIgnore []string
}
// TestStep is a single apply sequence of a test, done within the
@ -205,7 +208,7 @@ func Test(t TestT, c TestCase) {
log.Printf(
"[WARN] Test: Running ID-only refresh check on %s",
idRefreshCheck.Primary.ID)
if err := testIDOnlyRefresh(opts, step, idRefreshCheck); err != nil {
if err := testIDOnlyRefresh(c, opts, step, idRefreshCheck); err != nil {
log.Printf("[ERROR] Test: ID-only test failed: %s", err)
t.Error(fmt.Sprintf(
"ID-Only refresh test failure: %s", err))
@ -261,7 +264,7 @@ func UnitTest(t TestT, c TestCase) {
Test(t, c)
}
func testIDOnlyRefresh(opts terraform.ContextOpts, step TestStep, r *terraform.ResourceState) error {
func testIDOnlyRefresh(c TestCase, opts terraform.ContextOpts, step TestStep, r *terraform.ResourceState) error {
// TODO: We guard by this right now so master doesn't explode. We
// need to remove this eventually to make this part of the normal tests.
if os.Getenv("TF_ACC_IDONLY") == "" {
@ -323,6 +326,12 @@ func testIDOnlyRefresh(opts terraform.ContextOpts, step TestStep, r *terraform.R
}
actual := actualR.Primary.Attributes
expected := r.Primary.Attributes
// Remove fields we're ignoring
for _, v := range c.IDRefreshIgnore {
delete(actual, v)
delete(expected, v)
}
if !reflect.DeepEqual(actual, expected) {
// Determine only the different attributes
for k, v := range expected {