helper/resource: Add TestStep.PreventPostDestroyRefresh
- This is to allow easier testing of data sources which read data from resources created in the same scope
This commit is contained in:
parent
0075bd75fd
commit
84ab00d92e
|
@ -56,6 +56,10 @@ type TestCase struct {
|
|||
Providers map[string]terraform.ResourceProvider
|
||||
ProviderFactories map[string]terraform.ResourceProviderFactory
|
||||
|
||||
// PreventPostDestroyRefresh can be set to true for cases where data sources
|
||||
// are tested alongside real resources
|
||||
PreventPostDestroyRefresh bool
|
||||
|
||||
// CheckDestroy is called after the resource is finally destroyed
|
||||
// to allow the tester to test that the resource is truly gone.
|
||||
CheckDestroy TestCheckFunc
|
||||
|
@ -131,6 +135,10 @@ type TestStep struct {
|
|||
// looking to verify that a diff occurs
|
||||
ExpectNonEmptyPlan bool
|
||||
|
||||
// PreventPostDestroyRefresh can be set to true for cases where data sources
|
||||
// are tested alongside real resources
|
||||
PreventPostDestroyRefresh bool
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// ImportState testing
|
||||
//---------------------------------------------------------------
|
||||
|
@ -283,10 +291,12 @@ func Test(t TestT, c TestCase) {
|
|||
|
||||
// If we have a state, then run the destroy
|
||||
if state != nil {
|
||||
lastStep := c.Steps[len(c.Steps)-1]
|
||||
destroyStep := TestStep{
|
||||
Config: c.Steps[len(c.Steps)-1].Config,
|
||||
Check: c.CheckDestroy,
|
||||
Destroy: true,
|
||||
Config: lastStep.Config,
|
||||
Check: c.CheckDestroy,
|
||||
Destroy: true,
|
||||
PreventPostDestroyRefresh: c.PreventPostDestroyRefresh,
|
||||
}
|
||||
|
||||
log.Printf("[WARN] Test: Executing destroy step")
|
||||
|
|
|
@ -101,10 +101,12 @@ func testStep(
|
|||
}
|
||||
|
||||
// And another after a Refresh.
|
||||
state, err = ctx.Refresh()
|
||||
if err != nil {
|
||||
return state, fmt.Errorf(
|
||||
"Error on follow-up refresh: %s", err)
|
||||
if !step.Destroy || (step.Destroy && !step.PreventPostDestroyRefresh) {
|
||||
state, err = ctx.Refresh()
|
||||
if err != nil {
|
||||
return state, fmt.Errorf(
|
||||
"Error on follow-up refresh: %s", err)
|
||||
}
|
||||
}
|
||||
if p, err = ctx.Plan(); err != nil {
|
||||
return state, fmt.Errorf("Error on second follow-up plan: %s", err)
|
||||
|
|
Loading…
Reference in New Issue