refactor s3 bucket test to expect non-empty plan

pushing to master but paging @catsby for post-hoc review
This commit is contained in:
Paul Hinze 2016-01-05 17:37:54 -06:00
parent 96976222bb
commit a8d2ad3ebe
2 changed files with 21 additions and 12 deletions

View File

@ -188,6 +188,7 @@ func TestAccAWSS3Bucket_shouldFailNotFound(t *testing.T) {
testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"), testAccCheckAWSS3BucketExists("aws_s3_bucket.bucket"),
testAccCheckAWSS3DestroyBucket("aws_s3_bucket.bucket"), testAccCheckAWSS3DestroyBucket("aws_s3_bucket.bucket"),
), ),
ExpectNonEmptyPlan: true,
}, },
}, },
}) })

View File

@ -82,6 +82,10 @@ type TestStep struct {
// Destroy will create a destroy plan if set to true. // Destroy will create a destroy plan if set to true.
Destroy bool Destroy bool
// ExpectNonEmptyPlan can be set to true for specific types of tests that are
// looking to verify that a diff occurs
ExpectNonEmptyPlan bool
} }
// Test performs an acceptance test on a resource. // Test performs an acceptance test on a resource.
@ -273,13 +277,13 @@ func testStep(
// Now, verify that Plan is now empty and we don't have a perpetual diff issue // Now, verify that Plan is now empty and we don't have a perpetual diff issue
// We do this with TWO plans. One without a refresh. // We do this with TWO plans. One without a refresh.
if p, err := ctx.Plan(); err != nil { var p *terraform.Plan
if p, err = ctx.Plan(); err != nil {
return state, fmt.Errorf("Error on follow-up plan: %s", err) return state, fmt.Errorf("Error on follow-up plan: %s", err)
} else { }
if p.Diff != nil && !p.Diff.Empty() { if p.Diff != nil && !p.Diff.Empty() && !step.ExpectNonEmptyPlan {
return state, fmt.Errorf( return state, fmt.Errorf(
"After applying this step, the plan was not empty:\n\n%s", p) "After applying this step, the plan was not empty:\n\n%s", p)
}
} }
// And another after a Refresh. // And another after a Refresh.
@ -288,13 +292,17 @@ func testStep(
return state, fmt.Errorf( return state, fmt.Errorf(
"Error on follow-up refresh: %s", err) "Error on follow-up refresh: %s", err)
} }
if p, err := ctx.Plan(); err != nil { if p, err = ctx.Plan(); err != nil {
return state, fmt.Errorf("Error on second follow-up plan: %s", err) return state, fmt.Errorf("Error on second follow-up plan: %s", err)
} else { }
if p.Diff != nil && !p.Diff.Empty() { if p.Diff != nil && !p.Diff.Empty() && !step.ExpectNonEmptyPlan {
return state, fmt.Errorf( return state, fmt.Errorf(
"After applying this step and refreshing, the plan was not empty:\n\n%s", p) "After applying this step and refreshing, the plan was not empty:\n\n%s", p)
} }
// Made it here, but expected a non-empty plan, fail!
if step.ExpectNonEmptyPlan && (p.Diff == nil || p.Diff.Empty()) {
return state, fmt.Errorf("Expected a non-empty plan, but got an empty plan!")
} }
// Made it here? Good job test step! // Made it here? Good job test step!