Merge pull request #4247 from hashicorp/b-destroy-check-state
testing: Use a copy of pre-destroy state in destroy check
This commit is contained in:
commit
7f734d58cd
|
@ -247,6 +247,11 @@ func testStep(
|
||||||
log.Printf("[WARN] Test: Step plan: %s", p)
|
log.Printf("[WARN] Test: Step plan: %s", p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We need to keep a copy of the state prior to destroying
|
||||||
|
// such that destroy steps can verify their behaviour in the check
|
||||||
|
// function
|
||||||
|
stateBeforeApplication := state.DeepCopy()
|
||||||
|
|
||||||
// Apply!
|
// Apply!
|
||||||
state, err = ctx.Apply()
|
state, err = ctx.Apply()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -255,8 +260,14 @@ func testStep(
|
||||||
|
|
||||||
// Check! Excitement!
|
// Check! Excitement!
|
||||||
if step.Check != nil {
|
if step.Check != nil {
|
||||||
if err := step.Check(state); err != nil {
|
if step.Destroy {
|
||||||
return state, fmt.Errorf("Check failed: %s", err)
|
if err := step.Check(stateBeforeApplication); err != nil {
|
||||||
|
return state, fmt.Errorf("Check failed: %s", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if err := step.Check(state); err != nil {
|
||||||
|
return state, fmt.Errorf("Check failed: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue