testing: Use a copy of pre-destroy state in destroy check

In the acceptance testing framework, it is neccessary to provide a copy
of the state _before_ the destroy is applied to the check in order that
it can loop over resources to verify their destruction. This patch makes
a deep copy of the state prior to applying test steps which have the
Destroy option set and then passes that to the destroy check.
This commit is contained in:
James Nugent 2015-12-10 13:09:57 -05:00
parent 1b6f3558bb
commit e976d6e787

View File

@ -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,10 +260,16 @@ func testStep(
// Check! Excitement! // Check! Excitement!
if step.Check != nil { if step.Check != nil {
if step.Destroy {
if err := step.Check(stateBeforeApplication); err != nil {
return state, fmt.Errorf("Check failed: %s", err)
}
} else {
if err := step.Check(state); err != nil { if err := step.Check(state); err != nil {
return state, fmt.Errorf("Check failed: %s", err) return state, fmt.Errorf("Check failed: %s", err)
} }
} }
}
// 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.